Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-920 Modify rule S125: Add dotnet example #4589

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion rules/S125/csharp/rule.adoc
Original file line number Diff line number Diff line change
@@ -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...
}
----
Comment on lines +17 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not really inspired if you have a better idea 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about (but it's really nitpick):

int CalculateTotal(int[] prices)
{
    int total = 0;
    foreach (int price in prices)
    {
        total += price;
    }

    // int discount = 10;
    // total -= discount;

    return total;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have some real code in the method, but as I said, very nitpick and optional


==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
void Method(string s)
{
// Do something...
}
----


ifdef::env-github,rspecator-view[]

Expand Down
Loading