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:
github-actions[bot] 2025-03-19 14:37:23 +01:00 committed by GitHub
parent e94e4d8143
commit 91eadda5cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,8 @@
{
"tags": [
"clippy"
],
"defaultQualityProfiles": [
"Sonar way"
]
}

33
rules/S126/rust/rule.adoc Normal file
View 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