Compare commits

...

3 Commits

Author SHA1 Message Date
yassin-kammoun-sonarsource
457a65d315 Fix typo 2025-03-27 17:45:21 +01:00
yassin-kammoun-sonarsource
3318c3a29a Update RSPEC 2025-03-26 11:36:59 +01:00
yassin-kammoun-sonarsource
8830c7e5af Create rule S7454 2025-03-26 10:27:44 +00:00
3 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,24 @@
{
"title": "Numeric literal suffixes should not be mistyped",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7454",
"sqKey": "S7454",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,26 @@
== Why is this an issue?
Mistyped suffixes in numeric literals can lead to incorrect interpretations of the values intended by the developer. This is typically seen as a typo which could impact the functionality of the code. The rule does not however address integers that would not fit within the assumed type or specific valid groupings such as `_127` in decimal and octal numbers.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
let x = 2_32; // Noncompliant: Mistyped literal suffix
let y = 250_8; // Noncompliant: Mistyped literal suffix
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
let x = 2_i32; // Compliant: Correct literal suffix
let y = 250_u8; // Compliant: Correct literal suffix
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes