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

Add prefer-nullish-coalescing rule #1388

Closed
wants to merge 3 commits into from

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Jun 30, 2021

Fixes #471

@fregante
Copy link
Collaborator

Is this even safely possible without types?

@fisker
Copy link
Collaborator Author

fisker commented Jul 14, 2021

Is this even safely possible without types?

It's not safe, as you can see the changes, I was thinking maybe we can set this rule to warn by default, there is no harm without fix.

There are same concerns in the ESLint issue eslint/eslint#14037, and I don't think they will accept it.

I've already used this rule at my work with warn, this reminds me to use ?? every time when I use ||, and it did help.

I'm also trying to reduce false positives, I've excluded many cases with boolean value on the left, see this commit.

@fregante
Copy link
Collaborator

Unless the user disables warnings, warnings are still noisy enough that makes people wary of using || at all. Correct, common code should not cause warnings IMHO

@fisker
Copy link
Collaborator Author

fisker commented Jul 14, 2021

That's all I got in mind.

@sindresorhus
Copy link
Owner

I think this rule would be useful as something I would run once-in-a-while to catch cases where I forgot to use ??, but I agree, even warnings can be annoying when there are a lot of false-positives. So I think this rule should be off by default.

Alternatively, it would use type information when available: #347

@sindresorhus
Copy link
Owner

Closing for lack of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: prefer-nullish-coalescing
4 participants