+1
Planned

Enhancement suggestion for "Empty <anything>" rules (W501, W502, W505, W506)

Lübbe Onken 10 years ago updated by dummzeuch 10 years ago 3
In some cases it is desired to have an empty else, except, ... block.

The suggestion is to relax the rule under certain conditions. One condition would be that the empty block contains a comment, which hopefully explains why the block is empty.

Visually this could look like the following:
(X) W501 Empty EXCEPT block
(X) Accept comments
(X) W502 Empty FINALLY block
( ) Accept comments


with the above setting for the following code example:

procedure yeah(something, crazy:integer);
begin
try
try
something := crazy div 0;
except
// we can safely swallow the exceptions here
end;
finally
// nothing to clean up
end;
end;

Fixinsight would not warn about the empty exception, but warn about the empty finally block
That would be a great enhancement! That requires https://github.com/RomanYankovsky/DelphiAST/issues/39 to be implemented, but I've already made a few changes.
I am not sure whether it is a good idea to accept any comment there. Maybe it should only be a special kind of comment like
// nothing to do
or
// intenionally left empty
or maybe something FixInsight specific
// FixInsight: IgnoreEmpty

This would allow us to mark some particular blocks as intentionally empty while not generally disabling the warning.