Compare commits
4 Commits
master
...
rule/add-R
Author | SHA1 | Date | |
---|---|---|---|
![]() |
828072f64b | ||
![]() |
4881d94421 | ||
![]() |
0b08f51c46 | ||
![]() |
3bfac26d7b |
2
rules/S7457/metadata.json
Normal file
2
rules/S7457/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
24
rules/S7457/rust/metadata.json
Normal file
24
rules/S7457/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"title": "Calls to `step_by` that always panic should not be made",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "5min"
|
||||
},
|
||||
"tags": [
|
||||
"clippy"
|
||||
],
|
||||
"defaultSeverity": "Blocker",
|
||||
"ruleSpecification": "RSPEC-7457",
|
||||
"sqKey": "S7457",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"RELIABILITY": "HIGH"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
}
|
||||
}
|
28
rules/S7457/rust/rule.adoc
Normal file
28
rules/S7457/rust/rule.adoc
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
== Why is this an issue?
|
||||
Calling `.step_by(0)` on an iterator will cause the program to panic. This is likely an oversight and should be corrected to ensure program stability. If the intent is to cause a panic, it is clearer to use `panic!()` directly.
|
||||
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
for x in (0..100).step_by(0) { // Noncompliant: This will cause a panic.
|
||||
// ...
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
for x in (0..100).step_by(1) { // Compliant: Step by a valid positive integer.
|
||||
// ...
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero
|
Loading…
x
Reference in New Issue
Block a user