From 3cd4098dadf76c91acea4afe3cfdc7585fc594df Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Thu, 15 Aug 2024 12:13:18 +0200 Subject: [PATCH] Modify S2159 rule: Add Dart language --- rules/S2159/dart/rule.adoc | 32 +++++++++++++++++++++++++++----- rules/S2159/metadata.json | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/rules/S2159/dart/rule.adoc b/rules/S2159/dart/rule.adoc index 5dfa3842af5..95e6f2ab25a 100644 --- a/rules/S2159/dart/rule.adoc +++ b/rules/S2159/dart/rule.adoc @@ -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 @@ -12,7 +12,7 @@ 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!"); } } @@ -20,4 +20,26 @@ void f() { == Resources -* https://dart.dev/tools/linter-rules/unrelated_type_equality_checks[Dart Lint rule] \ No newline at end of file +=== 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[] diff --git a/rules/S2159/metadata.json b/rules/S2159/metadata.json index 115c149d5bc..e670acdb05f 100644 --- a/rules/S2159/metadata.json +++ b/rules/S2159/metadata.json @@ -1,5 +1,5 @@ { - "title": "Silly equality checks should not be made", + "title": "Unnecessary equality checks should not be made", "type": "BUG", "code": { "impacts": {