Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
ignorePattern,
useEslintrc: false,
fix: !args.check,
});
const report = engine.executeOnFiles([target]);
let errorCount = report.errorCount;
if (!args.check) {
// Write any fixes to disk
CLIEngine.outputFixes(report);
errorCount -= report.fixableErrorCount;
}
// Print the linting results
const formatter = CLIEngine.getFormatter();
const output = formatter(report.results);
console.log(output);
if (errorCount > 0) {
process.exit(1);
}
};
const lintingOptions = {};
if (cliOptions) {
cliOptions.forEach((option, index) => {
if (option.startsWith('--')) {
lintingOptions[option.replace('--', '')] = cliOptions[index + 1];
}
});
}
const cli = new CLIEngine(options);
const report = cli.executeOnFiles([ source ]);
const formatter = CLIEngine.getFormatter();
log(formatter(report.results));
// stop all remaining process when error occurred
if (report.errorCount > 0 && lintingOptions.exitOnError === 'true') {
warn('Further commands stopped due to errors in linting. Please fix them in order to continue!');
info('If you do not want to stop process due to the errors, you can set "exitOnError: false" in linting options.');
process.exit(1);
}
};
exports.resolveFormatter = (formatter) => {
// use ESLint to look up formatter references
if (typeof formatter !== 'function') {
// load formatter (module, relative to cwd, ESLint formatter)
formatter = CLIEngine.getFormatter(formatter) || formatter;
}
return formatter;
};
function printResults (results, formatStyle) {
const formatter = CLIEngine.getFormatter(formatStyle)
console.log(formatter(results.results, {}))
}
const getFormatter = (name) => {
const custom = ['text'];
if (custom.includes(name)) {
name = path.join(__dirname, 'formatters/', name + '.js');
}
return eslintCliEngine.getFormatter(name);
};
'use strict'
const CLIEngine = require('eslint').CLIEngine
const stylish = CLIEngine.getFormatter('stylish')
/**
* @typedef {Object} ESLintResultMessage
*
* @property {string} ruleId rules名
* @property {number} severity 错误级别
* @property {string} message 提示
* @property {number} line 开始行号
* @property {number} column 开始列号
* @property {string} nodeType nodeType
* @property {number} endLine 结束行号
* @property {number} endColumn 结束列号
*/
/**
* @typedef {Object} ESLintResult