Compare commits

...

2 Commits

Author SHA1 Message Date
yassin-kammoun-sonarsource
9f6baeaede Update RSPEC 2025-03-27 11:04:51 +01:00
yassin-kammoun-sonarsource
fd57f6b027 Create rule S7464 2025-03-27 09:53:09 +00:00
3 changed files with 54 additions and 0 deletions

View File

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

View File

@ -0,0 +1,24 @@
{
"title": "Infinite iterators should be finished off with a terminating operation",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7464",
"sqKey": "S7464",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,28 @@
== Why is this an issue?
Infinite iteration is usually an error in most cases, leading to programs that never terminate. While there are some acceptable use cases such as event streams, developers often unintentionally create infinite loops, causing resource exhaustion or unresponsive behavior.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
use std::iter;
iter::repeat(1_u8).collect::<Vec<_>>(); // Noncompliant: This creates an infinite iterator.
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
use std::iter;
iter::repeat(1_u8).take(5).collect::<Vec<_>>(); // Compliant: This creates a finite iterator by taking only the first 5 items.
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter