<commit_before>import glob from 'glob';
import path from 'path';
import { CLIEngine } from 'eslint';
import LintRunner from '../LintRunner';
import { clearLine } from '../cliUtils';

const ROOT_DIR = process.cwd();
const eslint = new CLIEngine({ cwd: ROOT_DIR });

export const check = (options) => {
  const {
    workers,
    paths,
    json
  } = options;

  const lintRunner = new LintRunner(workers);

  let filePaths = [];
  process.stdout.write('Reading files to be linted...[this may take a little bit]');
  for (let i = 0; i < paths.length; i++) {
    const files = glob.sync(paths[i], {});
    files.forEach((file) => {
      filePaths.push(file);
    });
  }

  let filesToProcess = 0;
  let lintResults = [];

  filePaths.map((file) => {
    if (eslint.isPathIgnored(path.join(ROOT_DIR, file)) || file.indexOf('eslint') !== -1) {
      return;
    }
    filesToProcess++;
    lintRunner.run({ cwd: ROOT_DIR }, [file])
      .then((results) => {
        const result = results[0];
        lintResults.push(result);
        filesToProcess--;
      });
  });

  const interval = setInterval(() => {
    clearLine();
    process.stdout.write(`Linting files...${filesToProcess} left to lint`);

    if (filesToProcess === 0) {
      clearInterval(interval);
      lintResults = lintResults.filter((result) => {
        return result.warningCount > 0 || result.errorCount > 0;
      });

      if (json) {
        console.log(JSON.stringify(lintResults));
      } else {
        const formatter = eslint.getFormatter();
        console.log(formatter(lintResults));
      }
      process.exit(lintResults.length > 0 ? 1 : 0);
    }
  }, 1000);
};<commit_msg>Simplify check command logic (#41)<commit_after>import glob from 'glob';
import { CLIEngine } from 'eslint';
import LintRunner from '../LintRunner';
import { flatten } from '../util';

const ROOT_DIR = process.cwd();
const eslint = new CLIEngine({ cwd: ROOT_DIR });

export const check = (options) => {
  const {
    workers,
    paths,
    json
  } = options;

  const lintRunner = new LintRunner(workers);
  
  const filePaths = flatten(paths.map(globPath => glob.sync(globPath)));

  lintRunner.run({ cwd: ROOT_DIR }, filePaths)
    .then((results) => {
      results = results.filter((result) => {
        return result.warningCount > 0 || result.errorCount > 0;
      });

      if (json) {
        console.log(JSON.stringify(results));
      } else {
        const formatter = eslint.getFormatter();
        console.log(formatter(results));
      }
      process.exit(results.length > 0 ? 1 : 0);
    });
};
{'fraction_non_alphanumeric': 0.15722049689440995, 'fraction_numerical': 0.008152173913043478, 'mean_word_length': 2.8520179372197307, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 19, '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': '4401576', 'n_tokens_mistral': 846, 'n_tokens_neox': 803, 'n_words': 192}