Create rule S7428 Case mismatches in pattern arms of match expressions should be avoided (#4769)
* Create rule S7428 * Update rule.adoc * Update metadata.json * Update metadata.json * Update metadata.json --------- Co-authored-by: sallaigy <sallaigy@users.noreply.github.com> Co-authored-by: Gyula Sallai <gyula.sallai@sonarsource.com>
This commit is contained in:
parent
8e35213fbb
commit
7b234485eb
2
rules/S7428/metadata.json
Normal file
2
rules/S7428/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
24
rules/S7428/rust/metadata.json
Normal file
24
rules/S7428/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"title": "Case mismatches in pattern arms of match expressions should be avoided",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"clippy"
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Blocker",
|
||||||
|
"ruleSpecification": "RSPEC-7428",
|
||||||
|
"sqKey": "S7428",
|
||||||
|
"scope": "All",
|
||||||
|
"defaultQualityProfiles": ["Sonar way"],
|
||||||
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"RELIABILITY": "HIGH"
|
||||||
|
},
|
||||||
|
"attribute": "LOGICAL"
|
||||||
|
}
|
||||||
|
}
|
32
rules/S7428/rust/rule.adoc
Normal file
32
rules/S7428/rust/rule.adoc
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
== Why is this an issue?
|
||||||
|
Case mismatches in pattern arms make some arms unreachable, likely leading to logic errors that can be difficult to debug.
|
||||||
|
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
match &*text.to_ascii_lowercase() {
|
||||||
|
"foo" => {},
|
||||||
|
"Bar" => {}, // Noncompliant: This arm is unreachable.
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
match &*text.to_ascii_lowercase() {
|
||||||
|
"foo" => {},
|
||||||
|
"bar" => {},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#match_str_case_mismatch
|
Loading…
x
Reference in New Issue
Block a user