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

Modify rule S2159: Add Dart language #4153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions rules/S2159/dart/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
== 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:
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 an object with `null`
* comparing an object with an unrelated primitive (e.g. a `String` with an `int`)
* comparing unrelated types

=== Noncompliant code example
Expand All @@ -12,12 +12,34 @@ Comparisons of dissimilar types will always return false. The comparison and all
----
void f() {
var a = "Hello, World!";
if (a == 42) {
if (a == 42) { // Noncompliant: comparing a String with an int
print("BOOM!");
}
}
----

== Resources

* https://dart.dev/tools/linter-rules/unrelated_type_equality_checks[Dart Lint rule]
=== 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[]
2 changes: 1 addition & 1 deletion rules/S2159/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Silly equality checks should not be made",
"title": "Unnecessary equality checks should not be made",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

"type": "BUG",
"code": {
"impacts": {
Expand Down