rspec/rules/S7430/rust/rule.adoc
github-actions[bot] ef9ace8117
Create rule S7430: splitn should not be used with a limit of 0 or 1 (#4771)
* 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>
2025-03-19 13:06:55 +00:00

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