sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

New rule: Attribute groups should only contain one attribute

Open fourls opened this issue 2 years ago • 2 comments

Prerequisites

  • [X] This rule has not already been suggested.
  • [X] This should be a new rule, not an improvement to an existing rule.
  • [X] This rule would be generally useful, not specific to my code or setup.

Suggested rule title

Attribute groups should only contain one attribute

Rule description

This rule would detect instances of multiple attributes within the same square brackets (e.g. [Foo, Bar]).

type
  [Foo, Bar('test')] // Noncompliant
  TMyClass = class(TObject)
  public
    [Foo]
    [Bar('test')] // Compliant
    procedure Baz;
  end;

Rationale

Having multiple attributes combined under a single square brackets is confusing, difficult to read, and error-prone. It's not immediately clear that there are multiple attributes applied, instead of a single attribute with constructor arguments.

fourls avatar Oct 31 '23 00:10 fourls

Agreed on the idea behind the rule - is there anything about this in the Embarcadero style guide?

cirras avatar Nov 14 '23 04:11 cirras

Don't believe so. This was the only reference I could find to this syntax feature, and it doesn't venture an opinion:

image

fourls avatar Nov 14 '23 04:11 fourls