Steeltoe icon indicating copy to clipboard operation
Steeltoe copied to clipboard

Address S125: Sections of code should not be commented out

Open bart-vmware opened this issue 3 years ago • 0 comments

Address existing violations of S125: Sections of code should not be commented out in the codebase and set severity to Info in Steeltoe.Debug.ruleset and to Warning in Steeltoe.Release.ruleset.

Note: The difference in severities between Debug/Release is to avoid distraction or hindrance while writing/debugging code.

To find existing violations, enable the rule (see above) and rebuild src/Steeltoe.All.sln to make them appear in the Output window.

To address the violations, choose from the following on a case-by-case basis:

  • If the commented out code serves no purpose, just remove it
  • If the code was accidentally commented out, uncomment it
  • If the commented out code represents non-trivial work to be potentially addressed in the future, remove the commented-out code and create a GitHub issue for it, labeled 'Type/enhancement'
  • If the commented out code exists for temporary purposes, such as debugging, verbose logging or measuring performance, either:
    • Uncomment and wrap into a method annotated with [System.Diagnostics.Conditional("DEBUG")], which prevents shipping the code while still getting compiler analysis on it (renames, find usages, etc.)
    • Add a private static boolean to the class to make it easy to toggle the code on/off, and move the commented-out code in a conditional statement:
      private static readonly bool IsPerformanceTracingEnabled = bool.Parse(bool.FalseString);
      
  • ~Suppress the violation in code using #pragma warning disable/restore, preceded by a justification comment if not obvious~

bart-vmware avatar Jul 28 '22 09:07 bart-vmware