-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [strict-boolean-expressions] refactor, add clearer error messages #1480
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): [strict-boolean-expressions] refactor, add clearer error messages #1480
Conversation
Thanks for the PR, @phaux! 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. |
BTW I also noticed that I want to add an option for this in a followup PR and a few others for cases that actually happen often in the wild and could be considered annoying and safe to allow via option. |
That PR mentioned:
... it would be great if that was disallowed. |
It's now trivial to have separate logic for each combination of types. The only question is whether we want a breaking change here instead of creating a new option that does this right. Here are the cases that I encounter often and could have an option to allow them:
|
Just to keep this PR focused, I've spun up #1515 to discuss new rule options |
I changed the check for a primitive type so that the string and number cases are handled separately. I also improved the handling of nested logical operators so that it now recurses over the operands all the way instead of checking only one level deep. This prevents double-reporting the whole expression and one of its operands at once, no matter how deeply nested they are. I think I'm done with this PR 👌 |
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.
question:
How does this rule handle never
types?
It looks like inspectVariantTypes
will not handle it.
Mostly LGTM. A few comments.
Thanks for your work here
Improved code style and made it so that the never type is always allowed 😎 |
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.
LGTM - thanks for your work here
Codecov Report
@@ Coverage Diff @@
## master #1480 +/- ##
==========================================
+ Coverage 95.47% 95.54% +0.07%
==========================================
Files 140 142 +2
Lines 6449 6579 +130
Branches 1851 1880 +29
==========================================
+ Hits 6157 6286 +129
+ Misses 107 106 -1
- Partials 185 187 +2
|
ignoreRhs
is too lenient #1118The positions of report messages also changed as a side effect of different logic for handling nested logical expressions. This was necessary to fix #1118