<commit_before>'use strict';

var semver = require('semver')
var path = require('path')

var DEFAULTS = {
  dir: process.cwd(),
  packageJsonName: 'package.json', //for testing
  nodeModulesName: 'node_modules', //for testing
  verbose: false
}

function mixin(target, source) {
  source = source || {}
  for (var key in source) {
    if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) {
      target[key] = source[key]
    }
  }
  return target
}

function getJson(path) {
  try {
    return require(path)
  } catch(e) {
    return null
  }
}

function violations(options) {
  var optionsKey = JSON.stringify(options)

  if (violations.list && violations.list[optionsKey]) return violations.list[optionsKey]

  options = mixin(options || {}, DEFAULTS)
  var packageJsonPath = path.join(options.dir, options.packageJsonName)
  var nodeModulesPath = path.join(options.dir, options.nodeModulesName)

  function log() {
    if (options.verbose) console.log.apply(console, Array.prototype.slice.apply(arguments))
  }

  function getInstalledPackageVersion(pkg) {
    var packageJson = getJson(path.join(nodeModulesPath, pkg, options.packageJsonName))
    return packageJson && packageJson.version
  }

  function getViolationsInDependenciesObject(obj) {
    return Object.keys(obj).map(function(dep) {
      var neededVersion = obj[dep].replace(/^.*\:\/\/.*#/,'') //gets the tag if using non-npm git repo
      var currentVersion = getInstalledPackageVersion(dep)

      log(dep + ' requires ' + neededVersion + ', has ' + currentVersion)
      if (!currentVersion) {
        return 'package ' + dep + ' is not installed'
      }
      if (!semver.satisfies(currentVersion, neededVersion)) {
        return 'package ' + dep + ' installed with ' + currentVersion + ' but required ' + neededVersion
      }
    }).filter(Boolean)
  }

  var packageJson = getJson(packageJsonPath)
  if (!packageJson) throw new Error('package.json is not at ' + packageJsonPath + ' (or invalid json)')

  var dependenciesObjects = [packageJson.dependencies, packageJson.devDependencies]

  var result = [].concat.apply([], dependenciesObjects.map(getViolationsInDependenciesObject))
  violations.list = violations.list || []
  violations.list[optionsKey] = result

  return result
}

function status(options) {
  return violations(options).length === 0
}<commit_msg>fixed eslint errors<commit_after>'use strict';

var semver = require('semver')
var path = require('path')

var DEFAULTS = {
  dir: process.cwd(),
  packageJsonName: 'package.json', //for testing
  nodeModulesName: 'node_modules', //for testing
  verbose: false
}

function mixin(target, source) {
  source = source || {}
  for (var key in source) {
    if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) {
      target[key] = source[key]
    }
  }
  return target
}

function getJson(jsonPath) {
  try {
    return require(jsonPath)
  } catch(e) {
    return null
  }
}

function violations(options) {
  var optionsKey = JSON.stringify(options)

  if (violations.list && violations.list[optionsKey]) {
    return violations.list[optionsKey]
  }

  options = mixin(options || {}, DEFAULTS)
  var packageJsonPath = path.join(options.dir, options.packageJsonName)
  var nodeModulesPath = path.join(options.dir, options.nodeModulesName)

  function log() {
    if (options.verbose) {
      console.log.apply(console, Array.prototype.slice.apply(arguments))
    }
  }

  function getInstalledPackageVersion(pkg) {
    var pkgJson = getJson(path.join(nodeModulesPath, pkg, options.packageJsonName))
    return pkgJson && pkgJson.version
  }

  function getViolationsInDependenciesObject(obj) {
    return Object.keys(obj).map(function(dep) {
      var neededVersion = obj[dep].replace(/^.*\:\/\/.*#/, '') //gets the tag if using non-npm git repo
      var currentVersion = getInstalledPackageVersion(dep)

      log(dep + ' requires ' + neededVersion + ', has ' + currentVersion)
      if (!currentVersion) {
        return 'package ' + dep + ' is not installed'
      }
      if (!semver.satisfies(currentVersion, neededVersion)) {
        return 'package ' + dep + ' installed with ' + currentVersion + ' but required ' + neededVersion
      }
    }).filter(Boolean)
  }

  var packageJson = getJson(packageJsonPath)
  if (!packageJson) {
    throw new Error('package.json is not at ' + packageJsonPath + ' (or invalid json)')
  }

  var dependenciesObjects = [packageJson.dependencies, packageJson.devDependencies]

  var result = [].concat.apply([], dependenciesObjects.map(getViolationsInDependenciesObject))
  violations.list = violations.list || []
  violations.list[optionsKey] = result

  return result
}

function status(options) {
  return violations(options).length === 0
}
{'fraction_non_alphanumeric': 0.12813487881981034, 'fraction_numerical': 0.00042149631190727084, 'mean_word_length': 3.852760736196319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4270874', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1413, 'n_words': 326}