forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoConstantsOnly.ql
More file actions
33 lines (30 loc) · 836 Bytes
/
NoConstantsOnly.ql
File metadata and controls
33 lines (30 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @name Abstract class only declares common constants
* @description Constants should be placed in a class where they belong logically, rather than in an
* abstract class containing just constants.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id cs/constants-only-interface
* @tags quality
* maintainability
* readability
*/
import csharp
class ConstantField extends Field {
ConstantField() {
this.isStatic() and this.isReadOnly()
or
this.isConst()
}
}
from Class c
where
c.isSourceDeclaration() and
c.isAbstract() and
c.getAMember() instanceof ConstantField and
forex(Member m | m = c.getAMember() |
m instanceof ConstantField or
m instanceof Constructor
)
select c, "Class '" + c.getName() + "' only declares common constants."