Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Configs: [prefer-nullish-coalescing] change default for ignoreConditionalTests to true #8243

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

Closed
2 tasks done
bradzacher opened this issue Jan 13, 2024 · 3 comments · Fixed by #8872
Closed
2 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue breaking change This change will require a new major version to be released locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config
Milestone

Comments

@bradzacher
Copy link
Member

Before You File a Proposal Please Confirm You Have Done The Following...

Description

Ref: #7955

IMO most codebases would prefer to avoid nullish coalescing in conditional tests.

Consider the downlevelled output:

if (x || y) { }

// vs

if (x ?? y) { } 
// downlevelled to
if (x != null ? x : y) { }

There's an extra check there that doesn't do anything.

The logic behind the latter is much harder to grasp exactly, IMO:

  • If x is truthy, then true,
  • If x is falsey and not nullish, then false,
  • Else the boolean coercion of y

vs the former:

  • If x is falsey then false
  • Else the boolean coercion of y

It's just A lot simpler to read and understand the non-nullish-coalescing form, IMO.

Impacted Configurations

No response

Additional Info

No response

@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look breaking change This change will require a new major version to be released preset config change Proposal for an addition, removal, or general change to a preset config labels Jan 13, 2024
@bradzacher bradzacher added this to the 7.0.0 milestone Jan 13, 2024
@JoshuaKGoldberg
Copy link
Member

Hmm. Hmm. I see what you're saying but don't align with it myself. I still like the benefits of the rule for safer null/undefined logic in conditions... Seeing it in ifs and the like was a little jarring for me at first, but now that I'm used to it I've come to prefer it this way.

Maybe this is an evaluating community engagement issue? cc @typescript-eslint/triage-team

@JoshuaKGoldberg
Copy link
Member

Meh coming back to this, having tried the rule out on some larger codebases, I'm leaning more towards where you are @bradzacher. I say let's mark this as accepting unless someone has more to say on it.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Apr 7, 2024
@JoshuaKGoldberg
Copy link
Member

#8872 was merged into the v8 branch. ✅

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue breaking change This change will require a new major version to be released locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config
Projects
None yet
2 participants