Skip to content
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

feat(eslint-plugin): [no-unnecessary-condition] remove option ignoreRHS #1163

Merged
merged 2 commits into from May 9, 2020

Conversation

Retsam
Copy link
Contributor

@Retsam Retsam commented Oct 30, 2019

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.

@typescript-eslint
Copy link
Contributor

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.

@bradzacher bradzacher added the breaking change This change will require a new major version to be released label Oct 30, 2019
@bradzacher bradzacher added this to the 3.0.0 milestone Oct 30, 2019
@Retsam
Copy link
Contributor Author

Retsam commented Oct 30, 2019

A side-effect of this change, checking logical expressions is a bit more fine-grained. Previously if(a && b && c) (with ignoreRHS off) would check the type of c and the type of (a && b) to determine if any part of the condition was unnecessary. Now the types of a, b, and c are checked independently.

This is an assuming that we can detect any unnecessary conditions by looking at a, b and c independently. I believe it's correct, that if a && b or a || b is unnecessary ("unnecessary" means "always truthy" or "always falsy"), then either a or b is unnecessary.

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
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #1163 into master will decrease coverage by 1.58%.
The diff coverage is 91.30%.

@@            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     
Flag Coverage Δ
#unittest 93.91% <91.30%> (?)
Impacted Files Coverage Δ
...es/eslint-plugin/src/configs/eslint-recommended.ts 100.00% <ø> (ø)
packages/eslint-plugin/src/rules/ban-ts-ignore.ts 100.00% <ø> (ø)
...nt-plugin/src/rules/consistent-type-definitions.ts 90.32% <ø> (ø)
...s/eslint-plugin/src/rules/interface-name-prefix.ts 100.00% <ø> (+16.66%) ⬆️
...es/eslint-plugin/src/rules/no-array-constructor.ts 100.00% <ø> (ø)
...ackages/eslint-plugin/src/rules/no-explicit-any.ts 92.85% <0.00%> (-7.15%) ⬇️
...slint-plugin/src/rules/no-unnecessary-qualifier.ts 96.15% <ø> (ø)
...nt-plugin/src/rules/no-untyped-public-signature.ts 100.00% <ø> (ø)
...s/eslint-plugin/src/rules/no-unused-expressions.ts 100.00% <ø> (ø)
...nt-plugin/src/rules/no-unused-vars-experimental.ts 91.48% <ø> (+0.09%) ⬆️
... and 138 more

@Retsam Retsam force-pushed the no-ignore-rhs branch 3 times, most recently from 9fc2747 to e34780a Compare January 28, 2020 20:35
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
@bradzacher bradzacher changed the title feat(eslint-plugin): [no-unnecessary-condition] remove ignoreRHS option feat(eslint-plugin): [no-unnecessary-condition] remove option ignoreRHS May 9, 2020
@bradzacher bradzacher changed the base branch from master to v3 May 9, 2020 23:27
@bradzacher bradzacher merged commit af7e31f into typescript-eslint:v3 May 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change This change will require a new major version to be released enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unnecessary-condition] What's the point of ignoreRhs: false option?
2 participants