[warning] proposal: do_not_check_equality_to_self
#56753
Labels
analyzer-warning
Issues with the analyzer's Warning codes
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
do_not_check_equality_to_self
Description
Checking equality to self will always return true and is likely a typo.
Details
Although good code tries to avoid it, sometimes two different variables or fields have similar names and types. It is then possible to mistakenly use one symbol where the programmer meant the other. This lint tries to prevent one such error, where a condition is in the form
a == a
ora != a
.Kind
This guards against hard-to-spot errors.
Bad Examples
Good Examples
Discussion
Just found this exact bug in my code, and only after seeing it happen in the step debugger. This wasn't flagged in any way. I'm using
package:flutter_lints/flutter.yaml
.I feel this is the kind of bug that linters were invented for. Stupid, hard to see as a human, easily detectable by the machine, and potentially infuriating ("why the hell doesn't this code run?").
I realize equality might be overridden for user types but even then, I think checking for
a == a
is probably a typo.Discussion checklist
The text was updated successfully, but these errors were encountered: