-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-unnecessary-boolean-literal-compare] add option to check nullable booleans #1983
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-boolean-literal-compare] add option to check nullable booleans #1983
Conversation
…ion to check nullable booleans
Thanks for the PR, @zachkirsch! 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. |
Codecov Report
@@ Coverage Diff @@
## master #1983 +/- ##
==========================================
+ Coverage 93.40% 93.43% +0.03%
==========================================
Files 174 174
Lines 7896 7938 +42
Branches 2256 2274 +18
==========================================
+ Hits 7375 7417 +42
Misses 247 247
Partials 274 274
|
thanks for the PR @zachkirsch - could you please provide some context behind this PR? To me it seems like this option removes a large portion of the usefulness of the rule as the most common case would be a nullable boolean. |
Yeah! Two reasons: Reason 1: Comparing nullable booleans to literal
Reason 2: Comparing nullable booleans to literal I see interface Props {
// whether to display title (defaults to true)
displayTitle?: boolean
}
...
public render() {
return (
<div>
{this.props.displayTitle !== false && renderTitle()}
... Before
I think this rule is still very useful with this option, as it
|
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.
mostly lgtm. one comment.
Thanks for your work
packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts
Outdated
Show resolved
Hide resolved
}; | ||
|
||
const defaults = { | ||
allowComparingNullableBooleans: true, |
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.
allowComparingNullableBooleans: true, | |
allowComparingNullableBooleans: false, |
…l-compare.ts Co-authored-by: Brad Zacher <[email protected]>
…al-compare.md Co-authored-by: Brad Zacher <[email protected]>
Sweet! I actually am having some second thoughts haha. I feel like auto-fixing Fixing What are your thoughts? We could also have additional config options that more granularly control which of these four comparisons are checked/fixed by the rule. |
Hmmm. Sorry, I did a quick eyeball and didn't notice the fix output. treat the false and nullish cases the same
treat the true and nullish cases the same
I think that is probably fine. The other option for the last two is to fix to something like |
Okay, I broke I also added some more docs to the rule's readme, including a table of what exactly the fixer does in each case. |
Lemme know if you need anything else from me! |
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!
No description provided.