-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDefaultControlNames.ql
More file actions
39 lines (36 loc) · 1.2 KB
/
DefaultControlNames.ql
File metadata and controls
39 lines (36 loc) · 1.2 KB
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
34
35
36
37
38
39
/**
* @name Windows controls with generated names
* @description Finds fields, corresponding to windows-forms controls, with generated names (such as "label1" or "PictureBox4").
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id cs/forms/default-control-name
* @tags readability
* naming
*/
import csharp
predicate controlName(string prefix)
{
prefix = "[Ll]abel" or
prefix = "[Bb]utton" or
prefix = "[Pp]anel" or
prefix = "[Rr]adio[Bb]utton" or
prefix = "[Pp]rop" or
prefix = "[Ss]atus[Ss]trip" or
prefix = "[Tt]able[Ll]ayout[Dd]esigner" or
prefix = "[Tt]ext[Bb]ox" or
prefix = "[Tt]ool[Ss]trip" or
prefix = "[Pp]icture[Bb]ox"
}
predicate usedInHumanWrittenCode(Field f) {
exists(File file |
f.getAnAccess().getFile() = file and
not file.getBaseName().toLowerCase().matches("%.designer.cs"))
}
from Field field, ValueOrRefType widget, string prefix
where widget.getABaseType*().hasQualifiedName("System.Windows.Forms.Control")
and field.getType() = widget
and field.getName().regexpMatch(prefix + "[0-9]+")
and controlName(prefix)
and usedInHumanWrittenCode(field)
select field, "Control '" + field.getName() + "' should have a meaningful name."