eqeqeq rule allow-undefined
See original GitHub issueWhat rule do you want to change?
Require === and !== (eqeqeq) https://eslint.org/docs/rules/eqeqeq#allow-null
Does this change cause the rule to produce more or fewer warnings?
In ECMA262:
null value is primitive value that represents the intentional absence of any object value.
undefined value is primitive value used when a variable has not been assigned a value.
In TypeScript team coding guidelines:
Use undefined. Do not use null.
https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#null-and-undefined
So i think comparing with the undefined literal should also can be allowed.
How will the change be implemented? (New option, new default behavior, etc.)? Please support allow-undefined.
Please provide some example code that this change will affect:
foo == null
foo == undefined
What does the rule currently do for this code?
foo == null // correct
foo == undefined // incorrect
What will the rule do after it’s changed?
foo == null // correct
foo == undefined // correct
Are you willing to submit a pull request to implement this change?
It’s my pleasure
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:26 (14 by maintainers)
Top GitHub Comments
I don’t think this change should be made in core for a few reasons:
Since this is purely stylistic, it falls under our new policy.
If you’re never using
null
, why not just usea === undefined
everywhere? It would be safer and more explicit. The way I read this guideline is that you should never usenull
to represent a null value for APIs you control. That doesn’t mean you wouldn’t have to usea === null
in your code, since there’s a good chance you’ll be interacting with someone else’s code (even if it’s just the Node builtin or DOM APIs) that may returnnull
.In the ECMA262 specification, [[Writable]] of
undefined
isfalse
. So i don’t think is problem to useundefined
in 2020.And most people use feature like ES Module and Class, they are always in strict mode. In strict mode will throw TypeError when
undefined = anything
.In the following url, Brendan Eich say in 2011/01/14 20:18:
Obviously, this is a bug that the author agreed.