From 74068df10adc9d4fe27eed60ae9b1e237d52473c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 15:22:56 +0000 Subject: [PATCH] Create rule S1862: Related "if/else if" statements should not have the same condition (#4687) * Add rust to rule S1862 * Add rule description * Fix errors * Add link to Clippy lint --------- Co-authored-by: sallaigy Co-authored-by: Gyula Sallai Co-authored-by: yassin-kammoun-sonarsource --- rules/S1862/rule.adoc | 1 - rules/S1862/rust/metadata.json | 8 +++++ rules/S1862/rust/rule.adoc | 53 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 rules/S1862/rust/metadata.json create mode 100644 rules/S1862/rust/rule.adoc diff --git a/rules/S1862/rule.adoc b/rules/S1862/rule.adoc index 1f1e26aa1b..6472b78d9a 100644 --- a/rules/S1862/rule.adoc +++ b/rules/S1862/rule.adoc @@ -1,4 +1,3 @@ == Why is this an issue? include::description.adoc[] - diff --git a/rules/S1862/rust/metadata.json b/rules/S1862/rust/metadata.json new file mode 100644 index 0000000000..014d70527b --- /dev/null +++ b/rules/S1862/rust/metadata.json @@ -0,0 +1,8 @@ +{ + "title": "Related \"if\/else if\" statements should not have the same condition", + "tags": [ + "clippy", + "unused", + "pitfall" + ] +} diff --git a/rules/S1862/rust/rule.adoc b/rules/S1862/rust/rule.adoc new file mode 100644 index 0000000000..29ebc26341 --- /dev/null +++ b/rules/S1862/rust/rule.adoc @@ -0,0 +1,53 @@ +== Why is this an issue? + +include::../description.adoc[] + +=== Noncompliant code example + +[source,rust,diff-id=1,diff-type=noncompliant] +---- +if param == 1 { + openWindow(); +} else if param == 2 { + closeWindow(); +} else if param == 1 { // Noncompliant + moveWindowToTheBackground(); +} +---- + +=== Compliant solution + +[source,rust,diff-id=1,diff-type=compliant] +---- +if param == 1 { + openWindow(); +} else if param == 2 { + closeWindow(); +} else if param == 3 { + moveWindowToTheBackground(); +} +---- + +== Resources + +=== Documentation + +* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond + +ifdef::env-github,rspecator-view[] + +''' +== Implementation Specification +(visible only on this page) + +include::../message.adoc[] + +include::../highlighting.adoc[] + +''' +== Comments And Links +(visible only on this page) + +include::../comments-and-links.adoc[] + +endif::env-github,rspecator-view[]