Skip to content

Add more exceptions to the EmptyBlock rule #221

Description

@Indigo744

Prerequisites

  • This improvement has not already been suggested.
  • This improvement should not be implemented as a separate rule.

Rule to improve

EmptyBlock

Improvement description

The EmptyBlock rule is currently defined as is:

Either remove or fill this block of code.
Most of the time a block of code is empty when a piece of code is really missing. An empty block should be either filled or removed.
Exceptions
Empty routine bodies (covered by the EmptyRoutine rule)
Empty except blocks (covered by the SwallowedException rule)
Case blocks that are empty apart from a comment

I think the last exception can be made broader: any blocks that are empty apart from a comment.

Example that triggers a finding related to this rule, but should not:

if condition then
begin
    // Comment explaining why this branch is empty
end;

Rationale

This is the way other scanner are implementing this rule.

And I think it makes sense! Comments are part of the code (and act as documentation).

For reference: https://sonarsource.github.io/rspec/#/rspec/S108/csharp

Exception : The rule ignores code blocks that contain comments.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to an existing featuregood first issueGood for newcomersruleImprovements or additions to rules

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions