rspec/rules/S126/rust/rule.adoc
github-actions[bot] 91eadda5cf
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>
2025-03-19 13:37:23 +00:00

34 lines
558 B
Plaintext

== 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