How to use the eslint.CLIEngine.getErrorResults function in eslint

To help you get started, we’ve selected a few eslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pelotom / runtypes / testSetup.js View on Github external
// Register babel so that it will transpile ES6 to ES5
// before our tests run.
require('babel-register')()

// Run ESLint
const { CLIEngine } = require('eslint')
const cli = new CLIEngine()
const { results } = cli.executeOnFiles(['src'])
const formatter = cli.getFormatter('stylish')
// Indent results to align with mocha output
const summary = formatter(results).replace(/\n/g, '\n  ')
console.log(summary)
if (CLIEngine.getErrorResults(results).length) {
  // Throw to short-circuit the test suite if we have linting errors
  const err = new Error()
  // Don't allow Mocha to print a useless stack trace
  err.stack = ''
  throw err
}
github postmanlabs / postman-runtime / npm / test-lint.js View on Github external
function (report, next) {
            var errorReport = ESLintCLIEngine.getErrorResults(report.results);

            // log the result to CLI
            console.info(ESLintCLIEngine.getFormatter()(report.results));
            // log the success of the parser if it has no errors
            (errorReport && !errorReport.length) && console.info('eslint ok!'.green);
            // ensure that the exit code is non zero in case there was an error
            next(Number(errorReport && errorReport.length) || 0);
        }
    ], exit);
github postmanlabs / postman-sandbox / npm / test-lint.js View on Github external
function (report, next) {
            var errorReport = ESLintCLIEngine.getErrorResults(report.results);
            // log the result to CLI
            console.log(ESLintCLIEngine.getFormatter()(report.results));
            // log the success of the parser if it has no errors
            (errorReport && !errorReport.length) && console.log(chalk.green('eslint ok!'));
            // ensure that the exit code is non zero in case there was an error
            next(Number(errorReport && errorReport.length) || 0);
        }
    ], exit);
github postmanlabs / newman / npm / test-lint.js View on Github external
function (report, next) {
            var errorReport = ESLintCLIEngine.getErrorResults(report.results);
            // log the result to CLI
            console.info(ESLintCLIEngine.getFormatter()(report.results));
            // log the success of the parser if it has no errors
            (errorReport && !errorReport.length) && console.info('eslint ok!'.green);
            // ensure that the exit code is non zero in case there was an error
            next(Number(errorReport && errorReport.length) || 0);
        }
    ], exit);
github graalvm / graaljs / tools / lint-js.js View on Github external
if (report.warningCount > 0) {
          for (let i = 0; i < results.length; ++i) {
            const result = results[i];
            if (result.errorCount === 0 && result.warningCount > 0) {
              result.warningCount = 0;
              result.messages = [];
            }
          }
        }
        process.send({ results: results, errorCount: report.errorCount });
      } else if (report.errorCount === 0) {
        // No errors, return number of successful lint operations
        process.send(files.length);
      } else {
        // One or more errors, return the error results only
        process.send(CLIEngine.getErrorResults(report.results));
      }
    } else if (typeof files === 'object') {
      // The master process is actually sending us our configuration and not a
      // list of files to lint
      config = files;
    }
  });
}
github tunnckoCore / opensource / @tunnckocore / jest-runner-eslint / dist / module / runner.js View on Github external
start,
      end: Date.now(),
      test: {
        path: testPath,
        title: 'ESLint'
      }
    });
  }

  const report = engine.executeOnFiles([testPath]);

  if (options.eslint.fix && !options.fixDryRun) {
    CLIEngine.outputFixes(report);
  }

  const message = engine.getFormatter(options.reporter)(options.quiet ? CLIEngine.getErrorResults(report.results) : report.results);

  if (report.errorCount > 0) {
    return fail({
      start,
      end: Date.now(),
      test: {
        path: testPath,
        title: 'ESLint',
        errorMessage: message
      }
    });
  }

  const tooManyWarnings = options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;

  if (tooManyWarnings) {
github tunnckoCore / opensource / @tunnckocore / jest-runner-eslint / src / runner.js View on Github external
end: Date.now(),
      test: {
        path: testPath,
        title: 'ESLint',
      },
    });
  }

  const report = engine.executeOnFiles([testPath]);

  if (options.fix && !options.fixDryRun) {
    CLIEngine.outputFixes(report);
  }

  const message = engine.getFormatter(options.reporter)(
    options.quiet ? CLIEngine.getErrorResults(report.results) : report.results,
  );

  if (report.errorCount > 0) {
    return fail({
      start,
      end: Date.now(),
      test: {
        path: testPath,
        title: 'ESLint',
        errorMessage: message,
      },
    });
  }

  const tooManyWarnings =
    options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;
github hjylewis / esplint / lib / eslint.js View on Github external
function runLint(eslintCli, files) {
  const report = eslintCli.executeOnFiles(files);
  const errorReport = CLIEngine.getErrorResults(report.results);
  const hasErrors = Boolean(errorReport.length);
  if (hasErrors) {
    const formatter = eslintCli.getFormatter();
    throw new EsplintError(
      `There were some ESLint errors. Fix them and try again.\n${chalk.reset(
        formatter(errorReport)
      )}`
    );
  }
  return report;
}
github wix / haste / packages / haste-task-eslint / src / index.js View on Github external
module.exports = ({ pattern, options = {} }, { fs }) => new Promise(async (resolve, reject) => {
  const files = await fs.read({ pattern });
  const cli = new CLIEngine(options);
  const filePaths = files.map(({ filename }) => filename);
  const report = cli.executeOnFiles(filePaths);

  const formatter = cli.getFormatter(options.formatter);
  options.fix && CLIEngine.outputFixes(report);

  const errors = CLIEngine.getErrorResults(report.results);

  if (errors.length) {
    return reject(formatter(report.results));
  }

  return resolve();
});