diff --git a/rules/S7430/metadata.json b/rules/S7430/metadata.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/rules/S7430/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S7430/rust/metadata.json b/rules/S7430/rust/metadata.json new file mode 100644 index 0000000000..111e53c457 --- /dev/null +++ b/rules/S7430/rust/metadata.json @@ -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" + } +} diff --git a/rules/S7430/rust/rule.adoc b/rules/S7430/rust/rule.adoc new file mode 100644 index 0000000000..047762cf79 --- /dev/null +++ b/rules/S7430/rust/rule.adoc @@ -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