rspec/rules/S2159/dart/rule.adoc
2024-08-15 15:03:58 +02:00

46 lines
1022 B
Plaintext

== Why is this an issue?
Comparisons of dissimilar types will always return `false`. The comparison and all its dependent code can simply be removed. This includes:
* comparing an object with `null`
* comparing an object with an unrelated primitive (e.g. a `String` with an `int`)
* comparing unrelated types
=== Noncompliant code example
[source,dart]
----
void f() {
var a = "Hello, World!";
if (a == 42) { // Noncompliant: comparing a String with an int
print("BOOM!");
}
}
----
== Resources
=== Documentation
* Dart Docs - https://dart.dev/tools/linter-rules/unrelated_type_equality_checks[Dart Linter rule - unrelated_type_equality_checks]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
The type of the right operand ('bool') isn't a subtype or a supertype of the left operand ('int').
=== Highlighting
The `==` operator or `!=` operator.
'''
== Comments And Links
(visible only on this page)
endif::env-github,rspecator-view[]