Compare commits
3 Commits
master
...
rule/add-R
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2b290d6865 | ||
![]() |
3776dc517b | ||
![]() |
73263207ac |
2
rules/S7456/metadata.json
Normal file
2
rules/S7456/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
24
rules/S7456/rust/metadata.json
Normal file
24
rules/S7456/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"title": "`skip(0)` should not be used on iterators",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"clippy"
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Major",
|
||||||
|
"ruleSpecification": "RSPEC-7456",
|
||||||
|
"sqKey": "S7456",
|
||||||
|
"scope": "All",
|
||||||
|
"defaultQualityProfiles": ["Sonar way"],
|
||||||
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"RELIABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "LOGICAL"
|
||||||
|
}
|
||||||
|
}
|
26
rules/S7456/rust/rule.adoc
Normal file
26
rules/S7456/rust/rule.adoc
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
== Why is this an issue?
|
||||||
|
Using `.skip(0)` on an iterator does nothing, which is likely to be a mistake. It is more probable that `.skip(1)` was intended to skip the first element, or if not, the `.skip(0)` call should be removed to avoid confusion and make the code clearer.
|
||||||
|
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
let v = vec![1, 2, 3];
|
||||||
|
let x = v.iter().skip(0).collect::<Vec<_>>(); // Noncompliant: .skip(0) does nothing
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
let v = vec![1, 2, 3];
|
||||||
|
let x = v.iter().collect::<Vec<_>>(); // Compliant: No .skip(0) call makes the intent clear
|
||||||
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero
|
Loading…
x
Reference in New Issue
Block a user