-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-unnecessary-condition] remove option ignoreRHS
#1163
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
Conversation
Thanks for the PR, @Retsam! 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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
A side-effect of this change, checking logical expressions is a bit more fine-grained. Previously This is an assuming that we can detect any unnecessary conditions by looking at If anyone can come up with a counter-example, where the two independently look necessary, but the combination is unnecessary, I think I can tweak the logic to account for that case. |
Codecov Report
@@ Coverage Diff @@
## master #1163 +/- ##
==========================================
- Coverage 95.49% 93.91% -1.59%
==========================================
Files 150 171 +21
Lines 6639 7787 +1148
Branches 1880 2238 +358
==========================================
+ Hits 6340 7313 +973
- Misses 112 217 +105
- Partials 187 257 +70
|
9fc2747
to
e34780a
Compare
The 'ignoreRHS' option was an unnecessary part of this lint rule; it forced the user to choose between false-negatives (e.g. if(expr && true)) or false positives `return expr && <ReactComponent>`. The new logic only checks the right hand side of a logical operator if the logical expression is in a conditional context: e.g. it's inside an if block, or it's the left hand side of another logical expression.
# Conflicts: # packages/eslint-plugin/src/rules/no-unnecessary-condition.ts # packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts
ignoreRHS
BREAKING CHANGE:
The 'ignoreRHS' option was an unnecessary part of this lint rule; it forced the user to choose between false-negatives (e.g. if(expr && true)) or false positives
return expr && <ReactComponent>
.The new logic only checks the right hand side of a logical operator if the logical expression is in a conditional context: e.g. it's inside an if block, or it's the left hand side of another logical expression.
Fixes #1017.