Embarcadero / SonarDelphi

Embarcadero's official version of the Sonar-Delphi plugin for use to analyze Delphi projects with SonarQube. Working to collect updates and contributions from other versions into this one and move if forward with new features.
GNU Lesser General Public License v2.1
63 stars 13 forks source link

Add more exceptions to the EmptyBlock rule #18

Closed Indigo744 closed 6 months ago

Indigo744 commented 6 months ago

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;

This is the way other scanner are implementing this rule. And 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.

fourls commented 6 months ago

Hi @Indigo744, this SonarDelphi fork is no longer maintained and does not contain an EmptyBlock rule.

From the rule description (which I wrote!) it looks like you're using the actively maintained integrated-application-development/sonar-delphi (the version on the Sonar Marketplace). If you re-raise your issue on that repository, we can discuss this improvement there.

Indigo744 commented 6 months ago

@fourls Indeed you're right! Sorry, I'll recreate there.