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.

Bug: [eslint-plugin-react-hooks] - exhaustive-deps autofix not working after 2.4.0

See original GitHub issue

Hi 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. image

Quick fix shows: image eslint --fix shows: image

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: image

Also it does add the missing deps using the same eslint --fix command.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
gaearoncommented, Mar 12, 2020

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.

8reactions
AlicanCcommented, Jul 10, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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