Skip to content

Commit

Permalink
Upgrade to ESLint 8 and require Node.js 12
Browse files Browse the repository at this point in the history
  • Loading branch information
ex1st committed Oct 14, 2021
1 parent 3de5e21 commit 1243d46
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -10,9 +10,9 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
2 changes: 1 addition & 1 deletion gruntfile.js
Expand Up @@ -3,7 +3,7 @@ module.exports = grunt => {
grunt.initConfig({
eslint: {
options: {
configFile: 'conf/eslint.json',
overrideConfigFile: 'conf/eslint.json',
rulePaths: ['conf/rules'],
quiet: true
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"test": "grunt"
Expand All @@ -28,7 +28,7 @@
],
"dependencies": {
"chalk": "^4.0.0",
"eslint": "^7.0.0"
"eslint": "^8.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -32,7 +32,7 @@ grunt.registerTask('default', ['eslint']);
grunt.initConfig({
eslint: {
options: {
configFile: 'conf/eslint.json',
overrideConfigFile: 'conf/eslint.json',
rulePaths: ['conf/rules']
},
target: ['file.js']
Expand Down
94 changes: 49 additions & 45 deletions tasks/eslint.js
@@ -1,62 +1,66 @@
'use strict';
const chalk = require('chalk');
const eslint = require('eslint');
const { ESLint } = require('eslint');

module.exports = grunt => {
grunt.registerMultiTask('eslint', 'Validate files with ESLint', function () {
const options = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1,
failOnError: true,
});

if (this.filesSrc.length === 0) {
grunt.log.writeln(chalk.magenta('Could not find any files to validate'));
return true;
}
grunt.registerMultiTask('eslint', 'Validate files with ESLint', async function () {
const done = this.async();

const formatter = eslint.CLIEngine.getFormatter(options.format);
try {
const { overrideConfigFile, rulePaths, ...options } = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1,
failOnError: true
});

if (!formatter) {
grunt.warn(`Could not find formatter ${options.format}`);
return false;
}
if (this.filesSrc.length === 0) {
grunt.log.writeln(chalk.magenta('Could not find any files to validate'));
return true;
}

const engine = new eslint.CLIEngine(options);
const engine = new ESLint({ overrideConfigFile, rulePaths });

let report;
try {
report = engine.executeOnFiles(this.filesSrc);
} catch (error) {
grunt.warn(error);
return false;
}
const formatter = await engine.loadFormatter(options.format);

if (options.fix) {
eslint.CLIEngine.outputFixes(report);
}
if (!formatter) {
grunt.warn(`Could not find formatter ${options.format}`);
return false;
}

let results = report.results;
let results = await engine.lintFiles(this.filesSrc);

if (options.quiet) {
results = eslint.CLIEngine.getErrorResults(results);
}
if (options.fix) {
await ESLint.outputFixes(results);
}

const output = formatter(results);
if (options.quiet) {
results = ESLint.getErrorResults(results);
}

if (options.outputFile) {
grunt.file.write(options.outputFile, output);
} else if (output) {
console.log(output);
}
const output = formatter.format(results);

const tooManyWarnings = options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;
if (options.outputFile) {
grunt.file.write(options.outputFile, output);
} else if (output) {
console.log(output);
}

if (report.errorCount === 0 && tooManyWarnings) {
grunt.warn(`ESLint found too many warnings (maximum: ${options.maxWarnings})`);
}
const { warningCount, errorCount } = results.reduce((count, { warningCount, errorCount }) => {
count.warningCount += warningCount;
count.errorCount += errorCount;
return count;
}, { warningCount: 0, errorCount: 0 });

return options.failOnError ? report.errorCount === 0 : 0;
const tooManyWarnings = options.maxWarnings >= 0 && warningCount > options.maxWarnings;

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

done(options.failOnError ? errorCount === 0 : 0);
} catch (err) {
done(err);
}
});
};
};

0 comments on commit 1243d46

Please sign in to comment.