Skip to content

Commit

Permalink
Upgrade to ESLint v6 and require Node.js 8
Browse files Browse the repository at this point in the history
Fixes #162
  • Loading branch information
sindresorhus committed Jun 30, 2019
1 parent a18f9ee commit 7707f60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "grunt"
Expand All @@ -20,22 +20,19 @@
],
"keywords": [
"gruntplugin",
"eslint",
"lint",
"validate",
"report",
"jshint",
"jslint",
"ecmascript",
"esprima"
"report"
],
"dependencies": {
"chalk": "^2.1.0",
"eslint": "^5.16.0"
"eslint": "^6.0.1"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-shell": "^2.1.0"
"grunt-shell": "^3.0.1"
},
"peerDependencies": {
"grunt": ">=1"
Expand Down
26 changes: 13 additions & 13 deletions tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const eslint = require('eslint');

module.exports = grunt => {
grunt.registerMultiTask('eslint', 'Validate files with ESLint', function () {
const opts = this.options({
const options = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1,
Expand All @@ -16,47 +16,47 @@ module.exports = grunt => {
return true;
}

const formatter = eslint.CLIEngine.getFormatter(opts.format);
const formatter = eslint.CLIEngine.getFormatter(options.format);

if (!formatter) {
grunt.warn(`Could not find formatter ${opts.format}`);
grunt.warn(`Could not find formatter ${options.format}`);
return false;
}

const engine = new eslint.CLIEngine(opts);
const engine = new eslint.CLIEngine(options);

let report;
try {
report = engine.executeOnFiles(this.filesSrc);
} catch (err) {
grunt.warn(err);
} catch (error) {
grunt.warn(error);
return false;
}

if (opts.fix) {
if (options.fix) {
eslint.CLIEngine.outputFixes(report);
}

let results = report.results;

if (opts.quiet) {
if (options.quiet) {
results = eslint.CLIEngine.getErrorResults(results);
}

const output = formatter(results);

if (opts.outputFile) {
grunt.file.write(opts.outputFile, output);
if (options.outputFile) {
grunt.file.write(options.outputFile, output);
} else if (output) {
console.log(output);
}

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

if (report.errorCount === 0 && tooManyWarnings) {
grunt.warn(`ESLint found too many warnings (maximum: ${opts.maxWarnings})`);
grunt.warn(`ESLint found too many warnings (maximum: ${options.maxWarnings})`);
}

return opts.failOnError ? report.errorCount === 0 : 0;
return options.failOnError ? report.errorCount === 0 : 0;
});
};

0 comments on commit 7707f60

Please sign in to comment.