Create rule S7423: Unit values should not be compared (#4764)
* Create rule S7423 * 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
e1ee16f500
commit
66bae183f4
2
rules/S7423/metadata.json
Normal file
2
rules/S7423/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
24
rules/S7423/rust/metadata.json
Normal file
24
rules/S7423/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"title": "Unit values should not be compared",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "5min"
|
||||
},
|
||||
"tags": [
|
||||
"clippy"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-7423",
|
||||
"sqKey": "S7423",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"RELIABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
}
|
||||
}
|
40
rules/S7423/rust/rule.adoc
Normal file
40
rules/S7423/rust/rule.adoc
Normal file
@ -0,0 +1,40 @@
|
||||
== Why is this an issue?
|
||||
|
||||
The unit type `()` is always equal to itself and using it in comparisons is either redundant or a mistake, often caused by accidental semicolon placement.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
fn foo() {}
|
||||
fn bar() {}
|
||||
fn baz() {}
|
||||
|
||||
if {
|
||||
foo();
|
||||
} == {
|
||||
bar();
|
||||
} {
|
||||
baz();
|
||||
} // Noncompliant: Comparing unit values.
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
fn foo() {}
|
||||
fn bar() {}
|
||||
fn baz() {}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
baz(); // Compliant: No unit comparison.
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
|
Loading…
x
Reference in New Issue
Block a user