Skip to content

Allow '==' to check for null and undefined in one go. #542

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
wants to merge 1 commit into from
Closed

Allow '==' to check for null and undefined in one go. #542

wants to merge 1 commit into from

Conversation

ludofischer
Copy link

Using == against null is a common pattern (see here for example). Since ESLint caters to it, should it not be allowed? Relevant ESLint documentation: http://eslint.org/docs/rules/eqeqeq

@ljharb
Copy link
Collaborator

ljharb commented Apr 20, 2016

@ludovicofischer are you still interested in landing this PR? if so, please rebase it on top of latest master. I'd be happy to land it.

@ludofischer
Copy link
Author

Hi, thanks for the heads up.

@ljharb
Copy link
Collaborator

ljharb commented Apr 20, 2016

@ludovicofischer I ended up committing it because I'm hoping to release soon :-) thanks for the contribution!

@spikebrehm
Copy link
Collaborator

Thanks @ljharb!

@mhofman
Copy link

mhofman commented Apr 20, 2016

Any reason not to go all the way and allow smart equals? basically same as allow-null with relaxation when the type is known, e.g. literals comparison or more importantly typeof

@ljharb
Copy link
Collaborator

ljharb commented Apr 20, 2016

@mhofman yes - that setting presents a refactoring hazard when one is changing a literal to a variable. == null is special, and otherwise, === should be used without exception.

@mhofman
Copy link

mhofman commented Apr 20, 2016

Well the lint rule should still catch it if the refactoring change didn't also change the == to === ;)

I don't care much for literals, but I find === overkill for typeof use cases.

@ljharb
Copy link
Collaborator

ljharb commented Apr 20, 2016

yes that is a fair point. but == null makes me uncomfortable enough; I don't want to train developers that == is ever OK.

jaylaw81 pushed a commit to appirio-digital/ads-best-practices that referenced this pull request Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants