-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [strict-boolean-expressions] Add allowNullable option #794
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] Add allowNullable option #794
Conversation
Add allowNullable option to strict-boolean-expressions rule
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 |
Codecov Report
@@ Coverage Diff @@
## master #794 +/- ##
==========================================
- Coverage 94.06% 94.06% -0.01%
==========================================
Files 113 113
Lines 4937 4952 +15
Branches 1378 1384 +6
==========================================
+ Hits 4644 4658 +14
Misses 166 166
- Partials 127 128 +1
|
I looked into adding a similar option to this rule awhile back, but ended up writing a new rule instead, which is still in PR (#699). If your intent is similar to mine (allow conditions that aren't strictly booleans, but avoid pointless conditions like |
@Retsam My use case is that I want to enforce being explicit to make my code more clear in situations like these:
I needed this option so I don't have to write I don't care about unnecessary conditions at all. I sometimes do "unnecessary" checks on purpose: function example(opts: Opts) {
// its required but I also want to check at runtime anyways
if (opts.someRequiredOpt == null) throw Error("...")
} |
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.
I think it's okay to add some more flexibility to this rule.
Thanks for doing this.
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.
Thanks for contributing, @phaux!
Add allowNullable option to strict-boolean-expressions rule. It should work the same as
allow-undefined-union
+allow-null-union
from tslint.Fixes #698