kibana/tasks/eslint.js
Spencer 0c736724b0 Upgrade eslint (#9357)
* upgrade eslint, all related deps, and config files

* replace gruntify-eslint with basic eslint-cli wrapper

* arrow-IIFEs must be invoked outside of the parens

* move import statements before their use

* reindent to satisfy new indentation check algorithm

* place missing semicolon

* ignore copy-pasted decode geohash code

* [grunt/eslint] fix argument spacing

* [gurnt/eslint] add comment about contents of report

* [grunt/tasks] use `export default`
2016-12-12 13:44:18 -07:00

45 lines
1.1 KiB
JavaScript

import { CLIEngine } from 'eslint';
const OPTION_DEFAULTS = {
paths: null,
cache: null,
fix: false
};
export default grunt => {
grunt.registerMultiTask('eslint', function () {
const options = this.options(OPTION_DEFAULTS);
if (!options.paths) {
grunt.fatal(new Error('No eslint.options.paths specified'));
return;
}
const cli = new CLIEngine({
cache: options.cache,
fix: options.fix,
cwd: grunt.config.get('root'),
});
// report includes an entire list of files checked and the
// fixes, errors, and warning for each.
const report = cli.executeOnFiles(options.paths);
// output fixes to disk
if (options.fix) {
CLIEngine.outputFixes(report);
}
// log the formatted linting report
const formatter = cli.getFormatter();
const errTypes = [];
if (report.errorCount > 0) errTypes.push('errors');
if (report.warningCount > 0) errTypes.push('warning');
if (!errTypes.length) return;
grunt.log.write(formatter(report.results));
grunt.fatal(`eslint ${errTypes.join(' & ')}`);
});
};