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-boolean-literal-compare] add nullish check option for fixer #2252

Closed
wants to merge 4 commits into from
Closed

Conversation

zachkirsch
Copy link
Contributor

As a followup to #1983, I figured that probably the most clear solution to a nullable-boolean comparison is an actual null check.

Example: myNullableBoolean === true. The current fixer will change it to myNullableBoolean, which is a bit simpler but doesn't address the ambiguity. IMO, the most clear way to do this is myNullableBoolean != null && myNullableBoolean. This is similar in motivation to strict-boolean-expressions.

This proposal adds a fixWithExplicitNullishCheck option to the rule to modify the behavior of the fixer. You can see what this option does here: https://github.com/zachkirsch/typescript-eslint/blob/zk/explicit-nullable-boolean-cmp/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md#nullable-boolean-expressions

@typescript-eslint
Copy link
Contributor

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

codecov bot commented Jun 24, 2020

Codecov Report

Merging #2252 into master will decrease coverage by 0.02%.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##           master    #2252      +/-   ##
==========================================
- Coverage   93.44%   93.42%   -0.03%     
==========================================
  Files         174      173       -1     
  Lines        7954     7804     -150     
  Branches     2282     2291       +9     
==========================================
- Hits         7433     7291     -142     
+ Misses        246      241       -5     
+ Partials      275      272       -3     
Flag Coverage Δ
#unittest 93.42% <93.33%> (-0.03%) ⬇️
Impacted Files Coverage Δ
...rc/rules/no-unnecessary-boolean-literal-compare.ts 97.82% <93.33%> (+8.21%) ⬆️
...-internal/src/rules/no-typescript-estree-import.ts 87.50% <0.00%> (-12.50%) ⬇️
packages/parser/src/scope/scopes.ts 100.00% <0.00%> (ø)
packages/parser/src/scope/scope-manager.ts 100.00% <0.00%> (ø)
packages/typescript-estree/src/simple-traverse.ts 95.00% <0.00%> (ø)
packages/typescript-estree/src/ts-estree/index.ts 100.00% <0.00%> (ø)
...pt-estree/src/ts-estree/estree-to-ts-node-types.ts 100.00% <0.00%> (ø)
packages/typescript-estree/src/visitor-keys.ts
.../typescript-estree/src/ts-estree/ast-node-types.ts
packages/experimental-utils/src/ts-estree.ts
... and 6 more

@zachkirsch zachkirsch closed this Jul 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant