Feature Request: How output stats can tell us eslint has fixed something or nothing
See original GitHub issueTell us about your environment
- ESLint Version: 5.11.1
- Node Version: 11.6.0
- npm Version: 6.5
What parser (default, Babel-ESLint, etc.) are you using? NOT applicable
Please show your full configuration: NOT applicable
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
eslint -c ./.eslintrc.js --fix --ext .js --ext .jsx .
What did you expect to happen?
{
results,
errorCount: 0,
warningCount: 5,
fixedCount: 2, <<<<<<<<<<<< new stat
fixableErrorCount: 0,
fixableWarningCount: 0,
usedDeprecatedRules
}
What actually happened? Please include the actual, raw output from ESLint.
I am fixing https://github.com/webpack-contrib/eslint-loader/pull/255#issue-228445668 and https://github.com/webpack-contrib/eslint-loader/pull/260#issue-241268921. I find that there is no way to know if the last run did fix something or nothing.
For example, the first run fixed 10 errors/warnings and saved to disk. It still has some unfixable errors/warnings. And the json output stats looks like
{
results,
errorCount: 0,
warningCount: 5,
fixableErrorCount: 0,
fixableWarningCount: 0,
usedDeprecatedRules
}
If I did nothing to the sources and then do the second run, the json output stats remains unchanged. Based on the two identical info, it cannot tell us eslint did fix/save/touch the file.
Currently, eslint-loader tries to stop the infinite loop issue with that predicates
if (config.fix && (res.results[0].fixableErrorCount > 0 || res.results[0].fixableWarningCount)) {
See https://github.com/webpack-contrib/eslint-loader/blob/f9d48ea55138c64231890f2c2825e3a454345836/index.js#L73
But it breaks the auto-fix and auto-save.
After I changed the predicates to if (config.fix)
, the infinite loop comes again. Then I realize that eslint output stats does not provide enough information about the last run which is how many fixableError and fixableWarning have been fixed in the last run.
With fixedCount
, it can tell eslint-loader does not need to save/touch the file again. Then the infinite loop issue can be solved by checking the value of fixedCount
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
If you use a
results
object where fixes have been applied, there will be anoutput
property containing the fixed source code instead of thesource
property. You can check whether theoutput
property exists in order to figure out whether fixes have been applied.Also see the documentation here: https://eslint.org/docs/developer-guide/nodejs-api#cliengineexecuteonfiles
Thanks for that. Let me try on eslint-loader. If it works, I will close it.