Skip to content

Commit dbaf9d5

Browse files
authoredOct 15, 2021
Upgrade to ESLint 8 and require Node.js 12 (#171)
1 parent 3de5e21 commit dbaf9d5

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed
 

‎.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: actions/setup-node@v1

‎gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = grunt => {
33
grunt.initConfig({
44
eslint: {
55
options: {
6-
configFile: 'conf/eslint.json',
6+
overrideConfigFile: 'conf/eslint.json',
77
rulePaths: ['conf/rules'],
88
quiet: true
99
},

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"engines": {
14-
"node": ">=10"
14+
"node": ">=12"
1515
},
1616
"scripts": {
1717
"test": "grunt"
@@ -28,7 +28,7 @@
2828
],
2929
"dependencies": {
3030
"chalk": "^4.0.0",
31-
"eslint": "^7.0.0"
31+
"eslint": "^8.0.0"
3232
},
3333
"devDependencies": {
3434
"grunt": "^1.0.1",

‎readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ grunt.registerTask('default', ['eslint']);
3232
grunt.initConfig({
3333
eslint: {
3434
options: {
35-
configFile: 'conf/eslint.json',
35+
overrideConfigFile: 'conf/eslint.json',
3636
rulePaths: ['conf/rules']
3737
},
3838
target: ['file.js']
@@ -55,7 +55,7 @@ grunt.initConfig({
5555

5656
## Options
5757

58-
See the [ESLint options](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
58+
See the [ESLint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
5959

6060
In addition the following options are supported:
6161

‎tasks/eslint.js

+50-45
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,67 @@
11
'use strict';
22
const chalk = require('chalk');
3-
const eslint = require('eslint');
3+
const { ESLint } = require('eslint');
44

55
module.exports = grunt => {
6-
grunt.registerMultiTask('eslint', 'Validate files with ESLint', function () {
7-
const options = this.options({
8-
outputFile: false,
9-
quiet: false,
10-
maxWarnings: -1,
11-
failOnError: true,
12-
});
13-
14-
if (this.filesSrc.length === 0) {
15-
grunt.log.writeln(chalk.magenta('Could not find any files to validate'));
16-
return true;
17-
}
6+
grunt.registerMultiTask('eslint', 'Validate files with ESLint', async function () {
7+
const done = this.async();
188

19-
const formatter = eslint.CLIEngine.getFormatter(options.format);
9+
try {
10+
const { format, quiet, maxWarnings, failOnError, outputFile, ...options } = this.options({
11+
outputFile: false,
12+
quiet: false,
13+
maxWarnings: -1,
14+
failOnError: true,
15+
format: "stylish"
16+
});
2017

21-
if (!formatter) {
22-
grunt.warn(`Could not find formatter ${options.format}`);
23-
return false;
24-
}
18+
if (this.filesSrc.length === 0) {
19+
grunt.log.writeln(chalk.magenta('Could not find any files to validate'));
20+
return true;
21+
}
2522

26-
const engine = new eslint.CLIEngine(options);
23+
const engine = new ESLint(options);
2724

28-
let report;
29-
try {
30-
report = engine.executeOnFiles(this.filesSrc);
31-
} catch (error) {
32-
grunt.warn(error);
33-
return false;
34-
}
25+
const formatter = await engine.loadFormatter(format);
3526

36-
if (options.fix) {
37-
eslint.CLIEngine.outputFixes(report);
38-
}
27+
if (!formatter) {
28+
grunt.warn(`Could not find formatter ${format}`);
29+
return false;
30+
}
3931

40-
let results = report.results;
32+
let results = await engine.lintFiles(this.filesSrc);
4133

42-
if (options.quiet) {
43-
results = eslint.CLIEngine.getErrorResults(results);
44-
}
34+
if (options.fix) {
35+
await ESLint.outputFixes(results);
36+
}
4537

46-
const output = formatter(results);
38+
if (quiet) {
39+
results = ESLint.getErrorResults(results);
40+
}
4741

48-
if (options.outputFile) {
49-
grunt.file.write(options.outputFile, output);
50-
} else if (output) {
51-
console.log(output);
52-
}
42+
const output = formatter.format(results);
5343

54-
const tooManyWarnings = options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;
44+
if (outputFile) {
45+
grunt.file.write(outputFile, output);
46+
} else if (output) {
47+
console.log(output);
48+
}
5549

56-
if (report.errorCount === 0 && tooManyWarnings) {
57-
grunt.warn(`ESLint found too many warnings (maximum: ${options.maxWarnings})`);
58-
}
50+
const { warningCount, errorCount } = results.reduce((count, { warningCount, errorCount }) => {
51+
count.warningCount += warningCount;
52+
count.errorCount += errorCount;
53+
return count;
54+
}, { warningCount: 0, errorCount: 0 });
5955

60-
return options.failOnError ? report.errorCount === 0 : 0;
56+
const tooManyWarnings = maxWarnings >= 0 && warningCount > maxWarnings;
57+
58+
if (errorCount === 0 && tooManyWarnings) {
59+
grunt.warn(`ESLint found too many warnings (maximum: ${maxWarnings})`);
60+
}
61+
62+
done(failOnError ? errorCount === 0 : 0);
63+
} catch (err) {
64+
done(err);
65+
}
6166
});
62-
};
67+
};

0 commit comments

Comments
 (0)
Please sign in to comment.