hapijs / eslint-config-hapi

Shareable ESLint config for the hapi ecosystem
Other
22 stars 23 forks source link

Update eqeqeq rule #34

Closed arb closed 8 years ago

arb commented 8 years ago

I'd like to propose adding "allow-null" to the eqeqeq rule. This would allow for checks for values of null or undefined to be done like:

function (value) {
  if (value == null) {
    console.log('value is null or undefined');
  }

While it's generally not a great idea to let JS do whatever it wants during coercion, in this one instance, I think the trade off is worth it as checking == null is a pretty common and understood pattern.

AdriVanHoudt commented 8 years ago

why not if (!value) or if (value === null || value === undefined) ?

cjihrig commented 8 years ago

if (!value) is not strictly equivalent.

I'm personally -1 on this, but it doesn't really matter anyway. This would have to get cleared in the hapi style guide.

arb commented 8 years ago

Why are you -1 on this? I agree though, this would have to go up the ladder.

cjihrig commented 8 years ago

I don't like it because it is more consistent to just use === everywhere. This one exception only saves you a few characters. I think foo === undefined || foo === null is faster too.

cjihrig commented 8 years ago

How about taking this up with the style guide (in hapijs/contrib I think), and if it gets OKed, I'll reopen this.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.