Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day. |
codecovbot commentedMay 6, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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
|
bradzacher commentedMay 6, 2020
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. |
zachkirsch commentedMay 7, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yeah! Two reasons: Reason 1: Comparing nullable booleans to literal
Reason 2: Comparing nullable booleans to literal I see interfaceProps{// whether to display title (defaults to true)displayTitle?:boolean}...publicrender(){return(<div>{this.props.displayTitle!==false&&renderTitle()} ... Before
I think this rule is still very useful with this option, as it
|
bradzacher left a comment
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| }; | ||
| 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.tsCo-authored-by: Brad Zacher <brad.zacher@gmail.com>
…al-compare.mdCo-authored-by: Brad Zacher <brad.zacher@gmail.com>
zachkirsch commentedJun 19, 2020
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. |
bradzacher commentedJun 19, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 |
zachkirsch commentedJun 19, 2020
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. |
zachkirsch commentedJun 20, 2020
Lemme know if you need anything else from me! |
bradzacher left a comment
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.