<commit_before>const TestSource = require('./test-source.js');
const Walker = require('./folder-walk.js');
const DefaultRunner = require('./test-runners/default.js');

class Runner {
  static get DEFAULT_RUNNER() {
    return 'default';
  }

  static get MOCHA_RUNNER() {
    return 'mocha';
  }

  static createError(err) {
    if (err) {
      switch (err.code) {
        case 'ENOENT':
          return new Error(`Cannot read test source location: ${err.path}`);
      }

      return err;
    }

    return false;
  }

  static checkTestSource(modules, testSource, settings) {
    // TODO: refactor this into TestSource
    if (modules && modules.length === 0) {
      let errorMessage = ['No tests defined! using source folder:', testSource];
      let err = new Error(errorMessage.join(' '));
      let detailed = [];

      if (settings.tag_filter && settings.tag_filter.length) {
        detailed.push(`- using tags filter: ${settings.tag_filter}`);
      }

      if (settings.skiptags && settings.skiptags.length) {
        detailed.push(`- using skiptags filter: ${settings.skiptags}`);
      }

      if (settings.filter) {
        detailed.push(`- using path filter: ${settings.filter}`);
      }

      if (settings.exclude) {
        detailed.push(`- using exclude match: ${settings.exclude}`);
      }

      if (detailed.length) {
        err.detailedErr = detailed.join('\n');
      }

      return err;
    }

    return true;
  }

  static getTestSource(settings, argv = {}) {
    const testSource = new TestSource(settings, argv);

    return new Walker(testSource.getSource(), settings, argv);
  }

  static readTestSource(settings, argv = {}) {
    const walker = Runner.getTestSource(settings, argv);

    return walker.readTestSource()
      .catch(err => {
        throw Runner.createError(err);
      })
      .then(modules => {
        let error = Runner.checkTestSource(modules, walker.testSource, settings);
        if (error instanceof Error) {
          throw error;
        }

        return modules;
      });
  }

  static create(settings, argv, addtOpts) {
    switch (settings.test_runner.type) {
      case Runner.DEFAULT_RUNNER:
        return new DefaultRunner(settings, argv, addtOpts);

      case Runner.MOCHA_RUNNER:
        const MochaRunner = require('./test-runners/mocha.js');

        return new MochaRunner(settings, argv, addtOpts);
    }
  }
}

module.exports = Runner;<commit_msg>fixed linter<commit_after>const TestSource = require('./test-source.js');
const Walker = require('./folder-walk.js');
const DefaultRunner = require('./test-runners/default.js');

class Runner {
  static get DEFAULT_RUNNER() {
    return 'default';
  }

  static get MOCHA_RUNNER() {
    return 'mocha';
  }

  static createError(err) {
    if (err) {
      switch (err.code) {
        case 'ENOENT':
          return new Error(`Cannot read test source location: ${err.path}`);
      }

      return err;
    }

    return false;
  }

  static checkTestSource(modules, testSource, settings) {
    // TODO: refactor this into TestSource
    if (modules && modules.length === 0) {
      let errorMessage = ['No tests defined! using source folder:', testSource];
      let err = new Error(errorMessage.join(' '));
      let detailed = [];

      if (settings.tag_filter && settings.tag_filter.length) {
        detailed.push(`- using tags filter: ${settings.tag_filter}`);
      }

      if (settings.skiptags && settings.skiptags.length) {
        detailed.push(`- using skiptags filter: ${settings.skiptags}`);
      }

      if (settings.filter) {
        detailed.push(`- using path filter: ${settings.filter}`);
      }

      if (settings.exclude) {
        detailed.push(`- using exclude match: ${settings.exclude}`);
      }

      if (detailed.length) {
        err.detailedErr = detailed.join('\n');
      }

      return err;
    }

    return true;
  }

  static getTestSource(settings, argv = {}) {
    const testSource = new TestSource(settings, argv);

    return new Walker(testSource.getSource(), settings, argv);
  }

  static readTestSource(settings, argv = {}) {
    const walker = Runner.getTestSource(settings, argv);

    return walker.readTestSource()
      .catch(err => {
        throw Runner.createError(err);
      })
      .then(modules => {
        let error = Runner.checkTestSource(modules, walker.testSource, settings);
        if (error instanceof Error) {
          throw error;
        }

        return modules;
      });
  }

  static create(settings, argv, addtOpts) {
    switch (settings.test_runner.type) {
      case Runner.DEFAULT_RUNNER:
        return new DefaultRunner(settings, argv, addtOpts);

      case Runner.MOCHA_RUNNER: {
        const MochaRunner = require('./test-runners/mocha.js');

        return new MochaRunner(settings, argv, addtOpts);
      }
    }
  }
}

module.exports = Runner;
{'fraction_non_alphanumeric': 0.1325128205128205, 'fraction_numerical': 0.00041025641025641023, 'mean_word_length': 2.580029368575624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2930673', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1455, 'n_words': 342}