Create rule S126: "if ... else if" constructs should end with "else" clauses (#4747)
* Add rust to rule S126 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
This commit is contained in:
parent
e94e4d8143
commit
91eadda5cf
8
rules/S126/rust/metadata.json
Normal file
8
rules/S126/rust/metadata.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"tags": [
|
||||||
|
"clippy"
|
||||||
|
],
|
||||||
|
"defaultQualityProfiles": [
|
||||||
|
"Sonar way"
|
||||||
|
]
|
||||||
|
}
|
33
rules/S126/rust/rule.adoc
Normal file
33
rules/S126/rust/rule.adoc
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
include::../description.adoc[]
|
||||||
|
|
||||||
|
=== Noncompliant code example
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
if x == 0 {
|
||||||
|
do_something();
|
||||||
|
} else if x == 1 {
|
||||||
|
do_something_else();
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
=== Compliant solution
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
if x == 0 {
|
||||||
|
do_something();
|
||||||
|
} else if x == 1 {
|
||||||
|
do_something_else();
|
||||||
|
} else {
|
||||||
|
panic!("Unexpected value for x");
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
|
Loading…
x
Reference in New Issue
Block a user