Skip to content

Commit fd6241c

Browse files
fourlscirras
authored andcommitted
Update AttributeName documentation
1 parent bc08f5a commit fd6241c

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
<h2>Why is this an issue?</h2>
12
<p>
2-
Attribute names should follow Pascal case and possess an <code>Attribute</code>
3-
suffix.
4-
<br />
5-
<code>attributeSuffix</code> can be <code>allowed</code> for an optional suffix,
6-
<code>required</code>, or <code>forbidden</code>.
3+
Code that follows a consistent naming convention is self-documenting. In Delphi, all custom
4+
attribute class names should be in PascalCase and end with <code>Attribute</code>. No prefix
5+
is required.
76
</p>
7+
<p>
8+
Custom attributes suffixed with <code>Attribute</code> may have the suffix omitted when
9+
used. This means that attributes can be defined with the same name (e.g. <code>MyCustom</code>
10+
and <code>MyCustomAttribute</code>), which may cause unexpected behaviour.
11+
</p>
12+
<p>
13+
To safeguard against this, the <code>Attribute</code> suffix should be used consistently.
14+
The suffix is also recommended for clarity, as attribute classes should not be used in other ways
15+
or instantiated directly.
16+
</p>
17+
<h2>How to fix it</h2>
18+
<p>Rename the attribute class name to follow the convention.</p>
19+
<h2>Resources</h2>
20+
<ul>
21+
<li>
22+
<a href="https://docwiki.embarcadero.com/RADStudio/en/Type_Declarations">
23+
Delphi's Object Pascal Style Guide: Type Declarations
24+
</a>
25+
</li>
26+
<li>
27+
<a href="https://docwiki.embarcadero.com/RADStudio/en/Declaring_Custom_Attributes_(RTTI)">
28+
RAD Studio documentation: Declaring Custom Attributes (RTTI)
29+
</a>
30+
</li>
31+
<li>
32+
<a href="https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types">
33+
.NET documentation: Names of Classes, Structs, and Interfaces
34+
</a>
35+
</li>
36+
</ul>

delphi-checks/src/main/resources/org/sonar/l10n/delphi/rules/community-delphi/AttributeName.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"MAINTAINABILITY": "LOW"
1313
}
1414
},
15-
"tags": [],
15+
"tags": ["confusing", "convention"],
1616
"defaultSeverity": "Minor",
1717
"scope": "ALL",
1818
"quickfix": "unknown"

0 commit comments

Comments
 (0)