-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Bug: [eslint-plugin-react-hooks] - exhaustive-deps autofix not working after 2.4.0 #18235
Comments
@melloc01 I'm facing exactly the same problem, I had to use eslint CLI to add them automatically. |
I have the same problem. IntelliJ Idea is not showing me autofix options anymore. package.json
.eslintrc
|
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: #18099 (comment) VS Code ESLint plugin already supports it. |
Not sure I am following here, I am using vscode and can now semi-manually fix the issue through the UI (understand that eslint will fill the dep array automatically if I click to fix it as shown in #18235 (comment)). Is there a way for this to be done automatically as part of auto-fixable problems like it used to be? I have auto-fix on save enabled and I find it saves me a lot of time compared to clicking the UI to fix the problem. As a side note, I barely ever had problems with the suggested fix before, one may always disable the rule for the line if needed. |
No, and intentionally so. This fix changes the behavior — in some cases, potentially introducing infinite loops. It's not safe to apply automatically. You need to read the suggestion and check if it makes sense. (When it doesn't, you usually need to fix other code rather than disable the rule btw.) |
I think |
Yes.. I stumbled upon the "infinite loop" problem caused by this rule quite a few times. While it had its issues, we programmers tend to get used to it and use it in our favor - (Ok! Fill it for me and I'll review it) - but I agree it should be a suggestion, it is just that we have to work on that muscle memory and get used to the new behavior. Thanks @gaearon |
I'm adding autofix back behind an appropriately named option for people who really need it. Note: if your IDE or lint setup actually fixes it automatically, you do not want this. This is only for people who use older IDEs that don't yet support Suggestions and who don't run this as an automatic step. |
Hi @gaearon! In your PR #18437 you write:
and in your comment above you write that you are adding autofix back, which confuses me a bit. I'm currently autofixinig my lint errors using
which works wonders for all my lint errors except I have Now, if I want to have autofix for exhausive deps, should I add I've tried
But ESLint just tells me
I've also tried
But get
|
ping @gaearon |
I am only adding it back behind a scary option because at FB, we have a custom ESLint VS Code extension that:
So I'm adding this as a workaround, but we only use it because we don't autofix on save. |
Again, you don't want to "autofix" this rule on save. This is a mistake. It will lead to problems. This rule is meant to be applied manually, with careful consideration in each case. (The concrete reason this option doesn't work though is because we haven't cut a release with it yet) |
This isn't a mistake worse than typing 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 If we didn't have |
@FrimJo Just in case if you didn't find why it's not working or for the benefit of others who will try it — there is a SPACE after option name |
Any update on this? |
@azz0r What exactly are you expecting to be updated? They started using code actions for this fix, if you want an old behavior, enable |
From Amcsi comment in CRA: They made it so To get autofixing to function add the following rule to your eslint
It works as well as it ever did! |
I only had infinite loop once through those years and the autofix was off (happened some days ago), I've just accepted the suggestion automatically without questioning as my muscular memory taught me after the autofix was remove lol Activated the autofix because the error is easy to spot and to know where it's happening, and it's very rare to happen. For my case, it was a key generator for each render; so I changed from state + 1 to Date.now(). |
Sorry to necropost, but one thing that I haven't seen discussed in this thread: the autofix will overwrite any dependencies already in place, so if you have one that isn't used in the effect, but you're using to trigger the effect, you'll lose it. This is kind of a weird example, but: React.useEffect(() => {
console.log(`networkStatus for ${entity} changed.`);
}, [networkStatus]); |
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.
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.The text was updated successfully, but these errors were encountered: