Description
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.