question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eqeqeq Rule Change Proposal: Allow only == undefined

See original GitHub issue

What rule do you want to change?

eqeqeq

Does this change cause the rule to produce more or fewer warnings?

Both fewer and more. See example below.

How will the change be implemented? (New option, new default behavior, etc.)?

It will be a new option. Currently we can do:

["error", "always", {"null": "ignore"}]

The new option would allow to set the rule this way:

["error", "always", {"undefined": "ignore"}]

Thus, that would allow the use of == and != only in the case one compares to undefined.

Please provide some example code that this change will affect:

It will be beneficial to people who want to use undefined exclusively, instead of null, but keep the possibility to check both null and undefined.

Although people might forbid null in their code, it still has to be checked in case it is returned in some third party library call, or JSON deserialized objects.

const foo = someThirdPartyFunction()
const bar = JSON.parse(json)

if (foo == undefined && bar != undefined) {
  // ...
}

if (foo == null && bar != null) {
  // ...
}

What does the rule currently do for this code?

Currently the following code is invalid :

// ["error", "always", {"null": "ignore"}]

const foo = someThirdPartyFunction()
const bar = JSON.parse(json)

if (foo == undefined && bar != undefined) {
  // ...
}

Currently the following code is valid :

// ["error", "always", {"null": "ignore"}]

const foo = someThirdPartyFunction()
const bar = JSON.parse(json)

if (foo == null && bar != null) {
  // ...
}

What will the rule do after it’s changed? The following code would be valid :

// ["error", "always", {"undefined": "ignore"}]

const foo = someThirdPartyFunction()
const bar = JSON.parse(json)

if (foo == undefined && bar != undefined) {
  // ...
}

The following code would be invalid :

// ["error", "always", {"undefined": "ignore"}]

const foo = someThirdPartyFunction()
const bar = JSON.parse(json)

if (foo == null && bar != null) {
  // ...
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kirly-afcommented, Dec 14, 2016

Hi @vitorbal, @platinumazure

Sorry I’ve been quite busy recently. I’ve updated the proposal, hopefully now there’s enough information.

EDIT: and btw, I’ll be happy to make a PR for it if the change is acceptable.

2reactions
not-an-aardvarkcommented, Jul 11, 2017

Thanks for your interest in improving ESLint. Unfortunately, it looks like this issue didn’t get enough support from the team and so I’m closing it. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach consensus after a long time tend to never do it, and as such, we close those issues. This doesn’t mean the idea isn’t interesting, just that it’s not something the team can commit to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't change ESlint eqeqeq option to "smart" - Stack Overflow
To turn off the eqeqeq rule everywhere: Open Windows Explorer with Windows Key + E; Paste exactly this into your URL bar: %USERPROFILE%...
Read more >
eqeqeq - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Fullstack part3 | Validation and ESLint
Let's change our handler for creating a new note so that it passes any potential exceptions to the error handler middleware: app.post('/api/notes', (request...
Read more >
JavaScript Equality Minesweeper - Hacker News
I only ever use == to do “x == null”, to check if x is undefined or null, ... So yeah, in practice...
Read more >
Airbnb JavaScript Style Guide()
const and let only exist in the blocks they are defined in. ... You can add new properties over time or change the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found