Create rule S7430: splitn
should not be used with a limit of 0 or 1 (#4771)
* Create rule S7430 * 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
fd50acb2e3
commit
ef9ace8117
2
rules/S7430/metadata.json
Normal file
2
rules/S7430/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
24
rules/S7430/rust/metadata.json
Normal file
24
rules/S7430/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"title": "`splitn` should not be used with a limit of 0 or 1",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "5min"
|
||||
},
|
||||
"tags": [
|
||||
"clippy"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-7430",
|
||||
"sqKey": "S7430",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"RELIABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
}
|
||||
}
|
30
rules/S7430/rust/rule.adoc
Normal file
30
rules/S7430/rust/rule.adoc
Normal file
@ -0,0 +1,30 @@
|
||||
== Why is this an issue?
|
||||
|
||||
When using `splitn` with zero or one splits, the function does not actually split the value, which is likely not the intended behavior.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
let s = "";
|
||||
for x in s.splitn(1, ":") { // Noncompliant
|
||||
// ..
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
let s = "";
|
||||
for x in s.splitn(2, ":") { // Compliant
|
||||
// ..
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_splitn
|
Loading…
x
Reference in New Issue
Block a user