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
prefer-nullish-coalescing rule #14037
Comments
Hi @koooge, thanks for the issue. It looks like there's not enough information for us to know how to help you. If you're reporting a bug, please be sure to include:
Requesting a new rule? Please see Proposing a New Rule for instructions. Requesting a rule change? Please see Proposing a Rule Change for instructions. If it's something else, please just provide as much additional information as possible. Thanks! |
Hi @koooge! Can you please update the proposal with the code examples? |
Hi @mdebruijne, I wrote simple code examples. I realized there is a bit different from typescript-eslint's. It seems not simply warn |
Thanks for the update!
So the rule would basically disallow |
At least in my experience, most of the time a short-circuit evaluation works out as it was intended when written. One downside of preferring coalescence over short-circuits is that usages where this.precision = config.precision ?? 4 Here we can infer by the necessity of nullish coalescing in the expression that const canViewContent = user.age > 21 ?? user.isExempt Whereas here we should ultimately ignore the usage of this.precision = config.precision ?? 4
const canViewContent = user.age > 21 ?? user.isExempt How about now? I understand the inclination to treat —Sorry I had more to say but my battery is dying; gotta run |
There are probably many places in a codebase where |
I agree that there's too much risk of false positives here. I'd lean toward leaving it in |
We won’t be moving forward with this, so closing. |
Hi there,
Please describe what the rule should do:
Almost same as typescript-eslint's prefer-nullish-coalescing.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md
I think that could be included in the eslint feature. It seems to depend on the type of information of typescript though.
What new ECMAScript feature does this rule relate to?
https://github.com/tc39/proposal-nullish-coalescing
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
Since Nullish Coalescing operator became a feature of EcmaScript not only typescript.
Are you willing to submit a pull request to implement this rule?
Not for now.
The text was updated successfully, but these errors were encountered: