Compare commits

...

2 Commits

Author SHA1 Message Date
yassin-kammoun-sonarsource
2260648cc8 Update RSPEC 2025-03-25 13:49:04 +01:00
yassin-kammoun-sonarsource
2e607bb4cb Add rust to rule S2185 2025-03-25 12:45:51 +00:00
4 changed files with 61 additions and 28 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -0,0 +1,7 @@
{
"title": "Erasing mathematical operations should not be performed",
"tags": [
"clumsy",
"clippy"
]
}

View 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