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:
parent
2713aeaed6
commit
164b14aedc
6
rules/S107/rust/metadata.json
Normal file
6
rules/S107/rust/metadata.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"tags": [
|
||||||
|
"brain-overload",
|
||||||
|
"clippy"
|
||||||
|
]
|
||||||
|
}
|
6
rules/S107/rust/noncompliant.adoc
Normal file
6
rules/S107/rust/noncompliant.adoc
Normal 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
27
rules/S107/rust/rule.adoc
Normal 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[]
|
11
rules/S107/rust/split-example.adoc
Normal file
11
rules/S107/rust/split-example.adoc
Normal 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) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
----
|
17
rules/S107/rust/struct-example.adoc
Normal file
17
rules/S107/rust/struct-example.adoc
Normal 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) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
----
|
Loading…
x
Reference in New Issue
Block a user