Skip to content
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

Rule suggestion: no-compare-to-new #1185

Open
rotu opened this issue Aug 8, 2023 · 1 comment
Open

Rule suggestion: no-compare-to-new #1185

rotu opened this issue Aug 8, 2023 · 1 comment
Labels
eslint-compat Related to compatibility with ESLint help wanted Extra attention is needed new-rule Suggestion to add a new lint rule

Comments

@rotu
Copy link
Contributor

rotu commented Aug 8, 2023

Using ===, ==, or switch with an object or array literal is always false.

The below are all examples of erroneous comparisons that could be flagged:

  • x === {}
  • switch (x) { case {}: /* ... */ }
  • Object.is(x, {}) (assuming Object.is has not been deleted or tampered with)

Additionally, if the type of x is known, the following could be flagged:

  • x == {} if x is not an object
  • x.includes({}), x.indexOf({}), x.lastIndexOf({}) if x is an Array
  • x.has({}), x.get({}), x.delete({}) if x is a Map or WeakMap
  • x.has({}), x.delete({}) if x is a Set or WeakSet

Similar to this suggested eslint rule:
eslint/eslint#15222

@bartlomieju
Copy link
Member

Seems reasonable 👍 contributions are welcome

@bartlomieju bartlomieju added help wanted Extra attention is needed new-rule Suggestion to add a new lint rule eslint-compat Related to compatibility with ESLint labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eslint-compat Related to compatibility with ESLint help wanted Extra attention is needed new-rule Suggestion to add a new lint rule
Projects
None yet
Development

No branches or pull requests

2 participants