From 164b14aedcb187d1eb8f1cf4a43bce1ba0009225 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:54:18 +0000 Subject: [PATCH] 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 Co-authored-by: yassin-kammoun-sonarsource Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> --- rules/S107/rust/metadata.json | 6 ++++++ rules/S107/rust/noncompliant.adoc | 6 ++++++ rules/S107/rust/rule.adoc | 27 +++++++++++++++++++++++++++ rules/S107/rust/split-example.adoc | 11 +++++++++++ rules/S107/rust/struct-example.adoc | 17 +++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 rules/S107/rust/metadata.json create mode 100644 rules/S107/rust/noncompliant.adoc create mode 100644 rules/S107/rust/rule.adoc create mode 100644 rules/S107/rust/split-example.adoc create mode 100644 rules/S107/rust/struct-example.adoc diff --git a/rules/S107/rust/metadata.json b/rules/S107/rust/metadata.json new file mode 100644 index 0000000000..e55944fb22 --- /dev/null +++ b/rules/S107/rust/metadata.json @@ -0,0 +1,6 @@ +{ + "tags": [ + "brain-overload", + "clippy" + ] +} diff --git a/rules/S107/rust/noncompliant.adoc b/rules/S107/rust/noncompliant.adoc new file mode 100644 index 0000000000..5ad4929307 --- /dev/null +++ b/rules/S107/rust/noncompliant.adoc @@ -0,0 +1,6 @@ +[source,rust] +---- +fn set_coordinates(x1: i32, y1: i32, z1: i32, x2: i32, y2: i32, z2: i32) { // Noncompliant + // ... +} +---- diff --git a/rules/S107/rust/rule.adoc b/rules/S107/rust/rule.adoc new file mode 100644 index 0000000000..9d60da2652 --- /dev/null +++ b/rules/S107/rust/rule.adoc @@ -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[] diff --git a/rules/S107/rust/split-example.adoc b/rules/S107/rust/split-example.adoc new file mode 100644 index 0000000000..d4f5d7f8d5 --- /dev/null +++ b/rules/S107/rust/split-example.adoc @@ -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) { + // ... +} +---- diff --git a/rules/S107/rust/struct-example.adoc b/rules/S107/rust/struct-example.adoc new file mode 100644 index 0000000000..a4b18690f7 --- /dev/null +++ b/rules/S107/rust/struct-example.adoc @@ -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) { + // ... +} +----