[ESLint] Consistently treat optional chaining as regular chaining#19273
Merged
gaearon merged 7 commits intofacebook:masterfrom Jul 7, 2020
Merged
[ESLint] Consistently treat optional chaining as regular chaining#19273gaearon merged 7 commits intofacebook:masterfrom
gaearon merged 7 commits intofacebook:masterfrom
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:
|
gaearon
commented
Jul 7, 2020
packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js
Outdated
Show resolved
Hide resolved
rickhanlonii
approved these changes
Jul 7, 2020
Member
rickhanlonii
left a comment
There was a problem hiding this comment.
The strategy makes sense, and all of the added tests will help re-add support for this the right way 👍
Contributor
|
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. |
Collaborator
Author
|
@radko93 Thanks, we're aware from the reports. :-) I am working on a proper fix. |
Collaborator
Author
Collaborator
Author
|
|
trueadm
pushed a commit
to trueadm/react
that referenced
this pull request
Jul 8, 2020
…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*
This was referenced Mar 15, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?.barasfoo.barfrom 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