← back to index

S125 — Sections of code should not be commented out

Language: C#  |  Type: CODE_SMELL  |  Severity: Major

Tags: unused

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

void Method(string s)
{
    // if (s.StartsWith('A'))
    // {
    //     s = s.Substring(1);
    // }

    // Do something...
}

Compliant solution

void Method(string s)
{
    // Do something...
}