Compare commits
2 Commits
master
...
rule/S2185
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2260648cc8 | ||
![]() |
2e607bb4cb |
@ -1,30 +1,2 @@
|
||||
{
|
||||
"title": "Do not perform unnecessary mathematical operations",
|
||||
"type": "CODE_SMELL",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
},
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "15min"
|
||||
},
|
||||
"tags": [
|
||||
"clumsy"
|
||||
],
|
||||
"extra": {
|
||||
"replacementRules": [],
|
||||
"legacyKeys": []
|
||||
},
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-2185",
|
||||
"sqKey": "S2185",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": [
|
||||
"Sonar way"
|
||||
],
|
||||
"quickfix": "unknown"
|
||||
}
|
||||
|
@ -1,2 +1,30 @@
|
||||
{
|
||||
"title": "Do not perform unnecessary mathematical operations",
|
||||
"type": "CODE_SMELL",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
},
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "15min"
|
||||
},
|
||||
"tags": [
|
||||
"clumsy"
|
||||
],
|
||||
"extra": {
|
||||
"replacementRules": [],
|
||||
"legacyKeys": []
|
||||
},
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-2185",
|
||||
"sqKey": "S2185",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": [
|
||||
"Sonar way"
|
||||
],
|
||||
"quickfix": "unknown"
|
||||
}
|
||||
|
7
rules/S2185/rust/metadata.json
Normal file
7
rules/S2185/rust/metadata.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Erasing mathematical operations should not be performed",
|
||||
"tags": [
|
||||
"clumsy",
|
||||
"clippy"
|
||||
]
|
||||
}
|
26
rules/S2185/rust/rule.adoc
Normal file
26
rules/S2185/rust/rule.adoc
Normal file
@ -0,0 +1,26 @@
|
||||
== Why is this an issue?
|
||||
|
||||
Erasing operations (e.g., any operation involving multiplying by zero, dividing zero by a value, or bitwise AND with zero) always result in zero regardless of the operands, which makes the expression unnecessary and can be replaced directly with zero. This simplifies the code and avoids potential confusion about the intent of the expression.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
let x = 1;
|
||||
let result = 0 * x; // Noncompliant: Result is always zero.
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
let x = 1;
|
||||
let result = 0; // Compliant: Simplified expression.
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
|
Loading…
x
Reference in New Issue
Block a user