Skip to content

Commit c514d36

Browse files
authored
Merge pull request #17197 from tamasvajk/fix/missing-xmldoc
C#: Exclude `System.Runtime.CompilerServices` attributes from XML doc…
2 parents 5248c8e + 63d07a9 commit c514d36

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

csharp/ql/src/Documentation/Documentation.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ predicate declarationHasXmlComment(Declaration d) { exists(getADeclarationXmlCom
4545
/** Whether a declaration should have documentation. */
4646
predicate isDocumentationNeeded(Modifiable decl) {
4747
decl.isUnboundDeclaration() and // Exclude constructed types and methods
48-
not exists(decl.(Attributable).getAnAttribute()) and // An attribute may serve to document
48+
not exists(Attribute a |
49+
a = decl.(Attributable).getAnAttribute() and
50+
not a.getType().hasFullyQualifiedName("System.Runtime.CompilerServices", _)
51+
) and // An attribute may serve to document
4952
decl.isPublic() and
5053
(
5154
// The documentation of the overridden method (e.g. in an interface) is sufficient.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Attributes in the `System.Runtime.CompilerServices` namespace are ignored when checking if a declaration requires documentation comments.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| documentation.cs:39:16:39:22 | method3 | Public method should be documented. |
22
| documentation.cs:51:18:51:23 | Class2 | Public class should be documented. |
33
| documentation.cs:74:12:74:17 | Class1 | Public constructor should be documented. |
4+
| documentation.cs:135:17:135:23 | method6 | Public method should be documented. |

csharp/ql/test/query-tests/Documentation/documentation.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,23 @@ public override int method1(int p1, int p2)
123123
// GOOD: Even if the overridden method is bad.
124124
/// <inheritdoc/>
125125
public override int method4<T>(int p1, int p2) { return p1; }
126+
127+
// GOOD: Has an attribute
128+
[My1]
129+
public void method5()
130+
{
131+
}
132+
133+
// BAD: Has only System.Runtime.CompilerServices attribute
134+
[System.Runtime.CompilerServices.My2]
135+
public void method6()
136+
{
137+
}
138+
}
139+
140+
internal class My1Attribute : Attribute { }
141+
142+
namespace System.Runtime.CompilerServices
143+
{
144+
internal class My2Attribute : Attribute { }
126145
}

0 commit comments

Comments
 (0)