-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [prefer-optional-chain] support if
statement as part of chain
#10137
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, @omril1! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
View your CI Pipeline Execution ↗ for commit cbfb329.
☁️ Nx Cloud last updated this comment at |
41e9ec4
to
075c034
Compare
…part of chain (issue-6309)
075c034
to
fd1c08d
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10137 +/- ##
==========================================
+ Coverage 87.58% 87.63% +0.05%
==========================================
Files 470 470
Lines 16095 16162 +67
Branches 4668 4688 +20
==========================================
+ Hits 14097 14164 +67
Misses 1642 1642
Partials 356 356
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Show resolved
Hide resolved
…issue-6309-prefer-optional-chain-support-if-statement
…l-chain-support-if-statement
…l-chain-support-if-statement
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.
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Show resolved
Hide resolved
…l-chain-support-if-statement
…de reachable for coverage
…l-chain-support-if-statement
…l-chain-support-if-statement
…l-chain-support-if-statement
@JoshuaKGoldberg ping, I saw a lot of your other work in the typescript/eslint/typescript-eslint repos, and I get that you are busy, but can we please advance this? |
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Show resolved
Hide resolved
…l-chain-support-if-statement
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.
Sorry for the delay! I've personally mostly stepped back from reviewing specific rule PRs, especially tricky ones like this. But the change is exciting and I want to be helpful - please do ping if I take weeks to get back to you again.
I think the autofixing/suggesting is still a little too brittle and can be reworked to better handle some comments. Left a few comments suggesting strategies.
? sourceCode.getCommentsBefore(tokenAfterAfterNodeTest) | ||
: []; // if (foo) /* this */ | ||
|
||
const commentsToReloacte = [ |
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.
[Typo]
const commentsToReloacte = [ | |
const commentsToRelocate = [ |
packages/eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts
Show resolved
Hide resolved
👋 Just checking in @omril1, is this still something you have time for? |
@JoshuaKGoldberg I think I'm giving up on this. The rule as it is currently doesn't handle all of the comments between the optional chaining nodes, and this PR is reusing all of the existing logic from I have no interest in expanding the scope of the PR, as it was already hard enough for me to integrate |
Ah, I'm sorry to hear that - especially since I think this is largely my fault for trying to sling a lot of annoying comments work on you. I think what was missing on my end was I'd thought there was existing comment handling that was being regressed here. But I think it'd be better to get this in and file a followup issue for the comments. Do you think you'd have time to just wontfix my comments there? |
I'm not sure what 'wontfix' mean, do you want me to just acknowledge it as out of scope in each discussion? I'll probably try to pick easier PRs to work on next time, I just liked how this rule helped simplify the awful legacy codebases I worked on 😄 |
Exactly: whatever you don't have scope to do, mention that in the conversation. And yeah, this is one of my favorite rules too. Really a pity what a nightmare working with its implementation is. 🥲 |
PR Checklist
if (x) x.something()
#6309Overview
Add an
allowIfStatements
option that would look atif
statements with a single call expression in their body and try to report a suggestion for a bigger chain that includes theif
'stest
node andbody
node