question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: How output stats can tell us eslint has fixed something or nothing

See original GitHub issue

Tell 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:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Dec 31, 2018

If you use a results object where fixes have been applied, there will be an output property containing the fixed source code instead of the source property. You can check whether the output 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

0reactions
wood1986commented, Dec 31, 2018

Thanks for that. Let me try on eslint-loader. If it works, I will close it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Rules - ESLint - Pluggable JavaScript Linter
"suggestion" means the rule is identifying something that could be done in a better way but no errors will occur if the code...
Read more >
How to Set Up ESLint Autofix and Prettier on Save in WebStorm
Let's see how you can set up WebStorm to run eslint --fix as well as Prettier ... Please make sure you have the...
Read more >
Changelog - JavaScript Standard Style
When you upgrade, consider running standard --fix to automatically format your code to match the current set of rules. Changed features. Update eslint...
Read more >
eslint - npm Package Health Analysis - Snyk
Based on project statistics from the GitHub repository for the npm package eslint, we found that it has been starred 21,924 times, and...
Read more >
Linting - SurviveJS
ESLint is unopinionated and doesn't have any rules by default so you should enable ... The --fix flag tells ESLint to fix problems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found