Bug: [eslint-plugin-react-hooks] - exhaustive-deps autofix not working after 2.4.0
See original GitHub issueHi there, after upgrading to the latest version the autofix does not automatically includes the missing deps, is this the expected behavior? I didn’t find any release notes of the lib so I couldn’t check if that was expected, also, I’d say, if done on purpose, this change should be on a major version, shouldn’t it?
The current behavior 2.4.0 or above
Some deps are missing.
Quick fix shows:
eslint --fix
shows:
But code is not being updated, although if I manually click it add the missing deps.
Expected behavior, 2.3.0
Noticed it shows another context menu:
Also it does add the missing deps using the same eslint --fix
command.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:20 (7 by maintainers)
Top Results From Across the Web
eslint-plugin-react-hooks - npm
Start using eslint-plugin-react-hooks in your project by running `npm i ... exhaustive-deps can be configured to validate dependencies of ...
Read more >eslint-plugin-react-hooks - npm package - Snyk
Ensure you're using the healthiest npm packages. Snyk scans all the packages in your projects for vulnerabilities and provides automated fix advice.
Read more >There is only ESLint fix option "Suppress ... for current line"
I solved this problem with npm install eslint-plugin-react-hooks@2.3.0 --save-dev and PyCharm ESLint config reload (disable and enable).
Read more >react-hooks/exhaustive-deps not showing in VS code
I have a .eslintrc file with the following rules: "rules": { ...
Read more >写React Hooks前必读 - 掘金
另外公司内部有个小姐姐补充道:eslint-plugin-react-hooks 从2.4.0版本开始,已经取消了exhaustive-deps 的autofix。所以,请尽量升级工程的lint插件 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is not a bug. We disabled the autofix because it created issues and wasn’t consistent with people’s expectations for ESLint autofix. Instead, we implemented the same functionality using the ESLint Suggestions API which was added in ESLint 6.7.0. You’ll need to wait for your IDE to support it: https://github.com/facebook/react/issues/18099#issuecomment-591647127
VS Code ESLint plugin already supports it.
This isn’t a mistake worse than typing
while (true) {}
and hitting save.When we are working with hooks with deps, we write an empty deps array, hit save, check how our code works, and if it causes an infinite loop or something we disable the rule and manually manage the deps.
We have an app with 358 components (all using hooks) and we disabled the rule just 3 times. The autofix works almost all the time and when it doesn’t work it never causes anything catastrophic.
If people are autofixing on commit/push/etc. and debugging for hours, I’d say the problem lies with their DX. The errors should always appear on the IDE and autofixing should always happen on save and not magically with a commit hook or something.
I understand that this isn’t really an autofix since autofixes should not change functionality, but there’s no other way to do this as easy as turning on
enableDangerousAutofixThisMayCauseInfiniteLoops
and hitting save.If we didn’t have
enableDangerousAutofixThisMayCauseInfiniteLoops
our DX with hooks would be significantly worse, so many many thanks for spending the time bringing this back and please keep supporting it until VSCode provides a way to apply the suggestion on save.