From e5a05283023b7230a9b1d55926658df37ece70a4 Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Tue, 24 Dec 2024 14:55:44 +0100 Subject: [PATCH] NET-920 Modify rule S125: Add dotnet example (#4589) --- rules/S125/csharp/rule.adoc | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/rules/S125/csharp/rule.adoc b/rules/S125/csharp/rule.adoc index fe598e7f71a..96e544d8da2 100644 --- a/rules/S125/csharp/rule.adoc +++ b/rules/S125/csharp/rule.adoc @@ -1,4 +1,40 @@ -include::../rule.adoc[] +== Why is this an issue? + +Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid. + +Commented-out code should be deleted and can be retrieved from source control history if required. + +== How to fix it + +Delete the commented out code. + +=== Code examples + +==== Noncompliant code example + +[source,csharp,diff-id=1,diff-type=noncompliant] +---- +void Method(string s) +{ + // if (s.StartsWith('A')) + // { + // s = s.Substring(1); + // } + + // Do something... +} +---- + +==== Compliant solution + +[source,csharp,diff-id=1,diff-type=compliant] +---- +void Method(string s) +{ + // Do something... +} +---- + ifdef::env-github,rspecator-view[]