![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7430 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
31 lines
610 B
Plaintext
31 lines
610 B
Plaintext
== 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
|