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 <sallaigy@users.noreply.github.com> Co-authored-by: Gyula Sallai <gyula.sallai@sonarsource.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
This commit is contained in:
parent
164b14aedc
commit
74068df10a
@ -1,4 +1,3 @@
|
|||||||
== Why is this an issue?
|
== Why is this an issue?
|
||||||
|
|
||||||
include::description.adoc[]
|
include::description.adoc[]
|
||||||
|
|
||||||
|
8
rules/S1862/rust/metadata.json
Normal file
8
rules/S1862/rust/metadata.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"title": "Related \"if\/else if\" statements should not have the same condition",
|
||||||
|
"tags": [
|
||||||
|
"clippy",
|
||||||
|
"unused",
|
||||||
|
"pitfall"
|
||||||
|
]
|
||||||
|
}
|
53
rules/S1862/rust/rule.adoc
Normal file
53
rules/S1862/rust/rule.adoc
Normal file
@ -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[]
|
Loading…
x
Reference in New Issue
Block a user