Update RSPEC

This commit is contained in:
yassin-kammoun-sonarsource 2025-03-27 11:04:51 +01:00
parent fd57f6b027
commit 9f6baeaede
2 changed files with 15 additions and 32 deletions

View File

@ -1,12 +1,13 @@
{ {
"title": "FIXME", "title": "Infinite iterators should be finished off with a terminating operation",
"type": "CODE_SMELL", "type": "BUG",
"status": "ready", "status": "ready",
"remediation": { "remediation": {
"func": "Constant\/Issue", "func": "Constant\/Issue",
"constantCost": "5min" "constantCost": "5min"
}, },
"tags": [ "tags": [
"clippy"
], ],
"defaultSeverity": "Major", "defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7464", "ruleSpecification": "RSPEC-7464",
@ -16,10 +17,8 @@
"quickfix": "unknown", "quickfix": "unknown",
"code": { "code": {
"impacts": { "impacts": {
"MAINTAINABILITY": "HIGH", "RELIABILITY": "MEDIUM"
"RELIABILITY": "MEDIUM",
"SECURITY": "LOW"
}, },
"attribute": "CONVENTIONAL" "attribute": "LOGICAL"
} }
} }

View File

@ -1,16 +1,6 @@
FIXME: add a description
// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
== Why is this an issue? == Why is this an issue?
FIXME: remove the unused optional headers (that are commented out) 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.
//=== What is the potential impact?
== How to fix it
//== How to fix it in FRAMEWORK NAME
=== Code examples === Code examples
@ -18,27 +8,21 @@ FIXME: remove the unused optional headers (that are commented out)
[source,rust,diff-id=1,diff-type=noncompliant] [source,rust,diff-id=1,diff-type=noncompliant]
---- ----
FIXME use std::iter;
iter::repeat(1_u8).collect::<Vec<_>>(); // Noncompliant: This creates an infinite iterator.
---- ----
==== Compliant solution ==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant] [source,rust,diff-id=1,diff-type=compliant]
---- ----
FIXME use std::iter;
iter::repeat(1_u8).take(5).collect::<Vec<_>>(); // Compliant: This creates a finite iterator by taking only the first 5 items.
---- ----
//=== How does this work? == Resources
=== Documentation
//=== Pitfalls * Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter
//=== Going the extra mile
//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks