-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[ESLint] Consistently treat optional chaining as regular chaining #19273
Conversation
facebook#19260)" This reverts commit 0f84b0f.
This is not ideal because our suggestions use normal chaining. But it gets rid of all current edge cases.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 26271d4:
|
packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strategy makes sense, and all of the added tests will help re-add support for this the right way 👍
Nice cleanup! |
Hey! It would be great to have a new version published with this, right now npm v4.0.5 breaks linters in projects. |
@radko93 Thanks, we're aware from the reports. :-) I am working on a proper fix. |
|
…cebook#19273) * Revert "Fix ExhaustiveDeps ESLint rule throwing with optional chaining (facebook#19260)" This reverts commit 0f84b0f. * Re-add a test from facebook#19260 * Remove all code for optional chaining support * Consistently treat optional chaining as regular chaining This is not ideal because our suggestions use normal chaining. But it gets rid of all current edge cases. * Add more tests * More consistency in treating normal and optional expressions * Add regression tests for every occurrence of Optional*
We've merged a bunch of PRs which added support for optional chaining to the ESLint rule about dependencies (#18820, #19008, #19062, #19260). However there was no single cohesive strategy behind them, and they led to crashes and edge cases because they attacked the symptoms rather than the root cause (the algorithm wasn’t designed to deal with optional chaining). There was no attempt to rethink the algorithm so the interim solutions have gradually made it broken and inconsistent. However, we did get new tests from them so they were still useful PRs. We just need to rethink our strategy.
As a first step I want to simplify this by getting back to where we were and removing the code that breaks algorithm’s assumptions. In particular, I am treating all
foo?.bar
asfoo.bar
from the dependency tracking perspective. The downside is that our error messages and fix suggestions will suggest regular chaining (but they will also be okay with optional chaining — so you can always fix them manually). The upside is that we can reason about what’s happening again because the inconsistencies are removed, and the algorithm only deals with regular property paths, just like before.This fixes a bunch of bugs, for which I’ve added regression tests.
As a follow-up to this, I think we should be able to figure out a simple solution that will preserve optional chaining where it makes sense in the messages and suggestions. However, I think this first step is still useful to get in as a base.
Best reviewed as individual commits