Create rule S3723: Array elements should be separated by commas (#4688)
* Add rust to rule S3723 * Update RSPEC * Remove tag --------- 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
8ae7a510c0
commit
40b6cf5d12
24
rules/S3723/rust/metadata.json
Normal file
24
rules/S3723/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"title": "Array elements should be separated by commas",
|
||||
"type": "CODE_SMELL",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "FORMATTED"
|
||||
},
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "2min"
|
||||
},
|
||||
"tags": [
|
||||
"clippy"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-3723",
|
||||
"sqKey": "S3723",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown"
|
||||
}
|
36
rules/S3723/rust/rule.adoc
Normal file
36
rules/S3723/rust/rule.adoc
Normal file
@ -0,0 +1,36 @@
|
||||
== Why is this an issue?
|
||||
|
||||
When defining arrays in Rust, it is possible to forget a comma between elements, especially when the elements are binary operator expressions that span multiple lines. This can lead to unexpected results, causing logical errors or runtime issues.
|
||||
|
||||
The origin of this problem is often due to oversight or formatting changes that split expressions across lines without adding the necessary comma.
|
||||
|
||||
== How to fix it
|
||||
|
||||
To fix this issue, add commas after each element or write the entire array on a single line.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
let a = &[
|
||||
-1, -2, -3 // Noncompliant: <= no comma here
|
||||
-4, -5, -6
|
||||
];
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
let a = &[
|
||||
-1, -2, -3,
|
||||
-4, -5, -6,
|
||||
];
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
|
Loading…
x
Reference in New Issue
Block a user