kibana/tasks/eslint.js
jasper f9690a6cbc Upgrade eslint (#9449)
Backports PR #9357

**Commit 1:**
upgrade eslint, all related deps, and config files

* Original sha: 054e798a93
* Authored by spalger <email@spalger.com> on 2016-08-24T23:39:11Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:04:20Z

**Commit 2:**
replace gruntify-eslint with basic eslint-cli wrapper

* Original sha: 71732e770f
* Authored by spalger <email@spalger.com> on 2016-09-02T21:33:02Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:41:36Z

**Commit 3:**
arrow-IIFEs must be invoked outside of the parens

* Original sha: b05662cd29
* Authored by spalger <email@spalger.com> on 2016-08-25T17:47:57Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:41:40Z

**Commit 4:**
move import statements before their use

* Original sha: 3572ab8e17
* Authored by spalger <email@spalger.com> on 2016-08-25T17:48:30Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:41:40Z

**Commit 5:**
reindent to satisfy new indentation check algorithm

* Original sha: b31dae18f5
* Authored by spalger <email@spalger.com> on 2016-08-25T17:49:47Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:41:58Z

**Commit 6:**
place missing semicolon

* Original sha: 7b39475116
* Authored by spalger <email@spalger.com> on 2016-09-06T22:27:10Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:42:04Z

**Commit 7:**
ignore copy-pasted decode geohash code

* Original sha: 3c02df9f4f
* Authored by spalger <email@spalger.com> on 2016-09-10T01:49:42Z
* Committed by spalger <spalger@users.noreply.github.com> on 2016-12-02T23:42:04Z

**Commit 8:**
Merge branch 'master' of github.com:elastic/kibana into upgrade/eslint-try2

* Original sha: 1224b1829a
* Authored by spalger <spalger@users.noreply.github.com> on 2016-12-10T04:14:32Z

**Commit 9:**
[grunt/eslint] fix argument spacing

* Original sha: 6fa2c6cad0
* Authored by spalger <spalger@users.noreply.github.com> on 2016-12-10T04:22:42Z

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

* Original sha: 71834ca7ec
* Authored by spalger <spalger@users.noreply.github.com> on 2016-12-10T07:59:11Z

**Commit 11:**
Merge branch 'master' of github.com:elastic/kibana into upgrade/eslint-try2

* Original sha: 76e77a7576
* Authored by spalger <spalger@users.noreply.github.com> on 2016-12-12T20:17:05Z

**Commit 12:**
[grunt/tasks] use `export default`

* Original sha: 803c0dacba
* Authored by spalger <spalger@users.noreply.github.com> on 2016-12-12T20:19:27Z
2016-12-12 15:49:09 -07:00

44 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(' & ')}`);
});
};