outmoded / hapi-contrib

Discussion forum for project contributors
Other
78 stars 25 forks source link

Style rule: eqeqeq and null #77

Closed arb closed 5 years ago

arb commented 8 years ago

Migrated from: https://github.com/continuationlabs/eslint-config-hapi/issues/34

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.

Marsup commented 8 years ago

Seems roughly equivalent in perf, OK for me.

devinivy commented 8 years ago

I personally much prefer the consistency of using === everywhere. I'm also not convinced that this is actually a widely understood pattern. Using x === null || x === undefined is explicit in what I would consider a very good way. If we want shorthand for checking null or undefined, maybe it's worth considering putting a utility in hoek.

cjihrig commented 8 years ago

My vote is to use x === null || x === undefined for consistency.

Marsup commented 8 years ago

Sucks for code coverage though, twice the test :p