From 86607c7d8618523935d431f38bf07d57004d449d Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini <114916336+cristian-ambrosini-sonarsource@users.noreply.github.com> Date: Fri, 29 Sep 2023 14:40:11 +0200 Subject: [PATCH] Modify rule S3241: Add C# snippet (#3182) --- rules/S3241/rule.adoc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rules/S3241/rule.adoc b/rules/S3241/rule.adoc index 2db1fbe35ce..0cd97a4a8b5 100644 --- a/rules/S3241/rule.adoc +++ b/rules/S3241/rule.adoc @@ -1,5 +1,18 @@ == Why is this an issue? -Private methods are clearly intended for use only within their own scope. When such methods return values that are never used by any of their callers, then clearly there is no need to actually make the return, and it should be removed in the interests of efficiency and clarity. +Private methods are intended for use only within their scope. If these methods return values that are not utilized by any calling functions, it indicates that the return operation is unnecessary. Removing such returns can enhance both efficiency and code clarity. +=== Noncompliant code example +[source,csharp] +---- +class SomeClass +{ + private int PrivateMethod() => 42; + + public void PublicMethod() + { + PrivateMethod(); // Noncompliant: the result of PrivateMethod is not used + } +} +----