Rule Change: Detect comparison to always new objects in no-constant-binary-expression #15357
Closed
1 task done
Labels
accepted
There is consensus among the team that this change meets the criteria for inclusion
archived due to age
This issue has been archived; please open a new issue for any further discussion
enhancement
This change enhances an existing feature of ESLint
rule
Relates to ESLint's core rules
Projects
What rule do you want to change?
no-constant-binary-expression
What change to do you want to make?
Generate more warnings
How do you think the change should be implemented?
A new default behavior
Example code
What does the rule currently do for this code?
Does not warn
What will the rule do after it's changed?
Warn
Participation
Additional comments
A
===
comparison between an any value and a newly constructed object is guaranteed to always be false and can be trivially detected based on syntax. This type of programming error can be easy to make for programmers coming from compare-by-value languages.I originally proposed this as a new rule in #15222 (you can see more context there) and it was rejected. However, now that I've realized we are calling my other proposed rule (#15222)
no-constant-binary-expression
I'm thinking that it makes sense to include this type of detection inno-constant-binary-expression
.In short:
foo === {}
orfoo === []
orfoo === (() => {})
are all statically provably constant binary expressions, and thus would make sense to flag as part of the new ruleno-constant-binary-expression
.Thoughts?
The text was updated successfully, but these errors were encountered: