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): [strict-boolean-expressions] Add allowNullable option #794

Merged
merged 4 commits into from Sep 12, 2019
Merged

feat(eslint-plugin): [strict-boolean-expressions] Add allowNullable option #794

merged 4 commits into from Sep 12, 2019

Conversation

phaux
Copy link
Contributor

@phaux phaux commented Aug 2, 2019

Add allowNullable option to strict-boolean-expressions rule. It should work the same as allow-undefined-union + allow-null-union from tslint.

Fixes #698

Add allowNullable option to strict-boolean-expressions rule
@typescript-eslint
Copy link
Contributor

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

@phaux phaux changed the title feat: 🎸 Add allowNullable option feat: 🎸 Add allowNullable option to strict-boolean-expressions rule Aug 2, 2019
@bradzacher bradzacher changed the title feat: 🎸 Add allowNullable option to strict-boolean-expressions rule feat(eslint-plugin): 🎸 Add allowNullable option to strict-boolean-expressions rule Aug 2, 2019
@phaux phaux changed the title feat(eslint-plugin): 🎸 Add allowNullable option to strict-boolean-expressions rule feat(eslint-plugin): [strict-boolean-expressions] Add allowNullable option Aug 3, 2019
@codecov
Copy link

codecov bot commented Aug 3, 2019

Codecov Report

Merging #794 into master will decrease coverage by <.01%.
The diff coverage is 93.75%.

@@            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
Impacted Files Coverage Δ
...int-plugin/src/rules/strict-boolean-expressions.ts 97.14% <93.75%> (-2.86%) ⬇️

@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Aug 6, 2019
@Retsam
Copy link
Contributor

Retsam commented Aug 6, 2019

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 true &&), you might check out that rule in PR; might be more straightforward than adding options to this rule.

@phaux
Copy link
Contributor Author

phaux commented Aug 7, 2019

@Retsam My use case is that I want to enforce being explicit to make my code more clear in situations like these:

  • arr.lengtharr.length > 0
  • obj.propobj.prop != null or "prop" in obj
  • strstr.length > 0 or str != ""

I needed this option so I don't have to write condition == true when condition is already a boolean but is also optional.

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("...")
}

Copy link
Member

@bradzacher bradzacher left a 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.

@bradzacher bradzacher added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Sep 3, 2019
Copy link
Member

@JamesHenry JamesHenry left a 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!

@JamesHenry JamesHenry removed the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Sep 12, 2019
@JamesHenry JamesHenry merged commit c713ca4 into typescript-eslint:master Sep 12, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
@phaux phaux deleted the strict-bool-allow-nullable branch February 27, 2021 15:03
@phaux phaux restored the strict-bool-allow-nullable branch February 27, 2021 15:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[strict-boolean-expressions] Add option to allow null and undefined
4 participants