<commit_before>'use strict';

const _ = require('lodash');
const linter = require('./services/linter');
const glob = require('./util/glob');
const mapPromise = require('./util/map-promise');
const reporters = require('./services/reporters');
const optionsParser = require('./util/options-parser');


function fnlint(options, cb) {
  cb = cb || _.noop;
  fnlint.promise(options)
    .then((result) => cb(null, result))
    .catch(cb);
}


fnlint.promise = function promise(options) {
  let parsedOptions = optionsParser(options);
  return mapPromise(parsedOptions.lintPackages, (lintPackage) => {
    return glob.promise(lintPackage.src)
      .then((files) => lintPackage.set('files', files));
  }).then((result) => {
    return reportResults(linter.lint(result));
  })
};


fnlint.sync = function sync(options) {
  let parsedOptions = optionsParser(options);
  return reportResults(linter.lint(_.map(parsedOptions.lintPackages, (lintPackage) => {
    return lintPackage.set('files', glob.sync(lintPackage.src));
  })));
};

function reportResults(results) {
  return _.tap(results, reporters.consoleReporter);
}

module.exports = fnlint;<commit_msg>Expose utils<commit_after>'use strict';

const _ = require('lodash');
const linter = require('./services/linter');
const glob = require('./util/glob');
const mapPromise = require('./util/map-promise');
const reporters = require('./services/reporters');
const optionsParser = require('./util/options-parser');
const util = require('./util/util');


function fnlint(options, cb) {
  cb = cb || _.noop;
  fnlint.promise(options)
    .then((result) => cb(null, result))
    .catch(cb);
}


fnlint.promise = function promise(options) {
  let parsedOptions = optionsParser(options);
  return mapPromise(parsedOptions.lintPackages, (lintPackage) => {
    return glob.promise(lintPackage.src)
      .then((files) => lintPackage.set('files', files));
  }).then((result) => {
    return reportResults(linter.lint(result));
  })
};


fnlint.sync = function sync(options) {
  let parsedOptions = optionsParser(options);
  return reportResults(linter.lint(_.map(parsedOptions.lintPackages, (lintPackage) => {
    return lintPackage.set('files', glob.sync(lintPackage.src));
  })));
};

function reportResults(results) {
  return _.tap(results, reporters.consoleReporter);
}

fnlint.util = util;

module.exports = fnlint;
{'fraction_non_alphanumeric': 0.1680101824352991, 'fraction_numerical': 0.0, 'mean_word_length': 4.954545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6045639', 'n_tokens_mistral': 730, 'n_tokens_neox': 723, 'n_words': 137}