Create rule S107: Functions should not have too many parameters (#4699)

* Add rust to rule S107

* Update RSPEC

* Remove tag

---------

Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com>
Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2025-03-19 14:54:18 +00:00 committed by GitHub
parent 2713aeaed6
commit 164b14aedc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,6 @@
{
"tags": [
"brain-overload",
"clippy"
]
}

View File

@ -0,0 +1,6 @@
[source,rust]
----
fn set_coordinates(x1: i32, y1: i32, z1: i32, x2: i32, y2: i32, z2: i32) { // Noncompliant
// ...
}
----

27
rules/S107/rust/rule.adoc Normal file
View File

@ -0,0 +1,27 @@
:language: rust
include::../rule.adoc[]
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../parameters.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]

View File

@ -0,0 +1,11 @@
[source,rust]
----
// Each function does a part of what the original setCoordinates function was doing, so confusion risks are lower
fn set_origin(x: i32, y: i32, z: i32) {
// ...
}
fn set_size(width: i32, height: i32, depth: i32) {
// ...
}
----

View File

@ -0,0 +1,17 @@
[source,rust]
----
struct Point {
x: i32,
y: i32,
}
impl Point {
fn new(x: i32, y: i32) -> Point {
Point { x, y }
}
}
fn set_coordinates(p1: &mut Point, p2: &Point) {
// ...
}
----