New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to ESLint 8 and require Node.js 12 #171
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,67 @@ | ||
'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 { format, quiet, maxWarnings, failOnError, outputFile, ...options } = this.options({ | ||
outputFile: false, | ||
quiet: false, | ||
maxWarnings: -1, | ||
failOnError: true, | ||
format: "stylish" | ||
}); | ||
|
||
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(options); | ||
|
||
let report; | ||
try { | ||
report = engine.executeOnFiles(this.filesSrc); | ||
} catch (error) { | ||
grunt.warn(error); | ||
return false; | ||
} | ||
const formatter = await engine.loadFormatter(format); | ||
|
||
if (options.fix) { | ||
eslint.CLIEngine.outputFixes(report); | ||
} | ||
if (!formatter) { | ||
grunt.warn(`Could not find formatter ${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 (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 (outputFile) { | ||
grunt.file.write(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 = maxWarnings >= 0 && warningCount > maxWarnings; | ||
|
||
if (errorCount === 0 && tooManyWarnings) { | ||
grunt.warn(`ESLint found too many warnings (maximum: ${maxWarnings})`); | ||
} | ||
|
||
done(failOnError ? errorCount === 0 : 0); | ||
} catch (err) { | ||
done(err); | ||
} | ||
}); | ||
}; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing the option name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @sindresorhus because 'configFile' option is deprecated in v8. If you run the test with that option eslint prints the error message: