forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlNamePrefixes.ql
More file actions
107 lines (104 loc) · 2.89 KB
/
ControlNamePrefixes.ql
File metadata and controls
107 lines (104 loc) · 2.89 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @name ASP.NET control name prefixes
* @description Including standard prefixes in the field names of
* ASP.NET Web / HTML controls makes code easier to understand.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id cs/web/unprefixed-control-name
* @tags quality
* maintainability
* readability
*/
import csharp
string prefix(string qualifier, string typename) {
qualifier = "System.Web.UI.WebControls" and
(
typename = "Label" and result = "lbl"
or
typename = "TextBox" and result = "txt"
or
typename = ["Button", "LinkButton"] and result = "btn"
or
typename = "ImageButton" and result = "ibtn"
or
typename = "Hyperlink" and result = "hpl"
or
typename = "DropDownList" and result = "cmb"
or
typename = "ListBox" and result = "lst"
or
typename = "Datagrid" and result = "dgr"
or
typename = "Datalist" and result = "dtl"
or
typename = "Repeater" and result = "rpt"
or
typename = "CheckBox" and result = "chk"
or
typename = "CheckBoxList" and result = "chklst"
or
typename = "RadioButtonList" and result = "radlst"
or
typename = "RadioButton" and result = "rad"
or
typename = "Image" and result = "img"
or
typename = "Panel" and result = "pnl"
or
typename = "PlaceHolder" and result = "plh"
or
typename = "Calendar" and result = "cal"
or
typename = "AdRotator" and result = "adr"
or
typename = "Table" and result = "tbl"
or
typename = "RequiredFieldValidator" and result = "rfv"
or
typename = "CompareValidator" and result = "cmv"
or
typename = "RegularExpressionValidator" and result = "rev"
or
typename = "CustomValidator" and result = "csv"
or
typename = "ValidationSummary" and result = "vsm"
or
typename = "XML" and result = "xml"
or
typename = "Literal" and result = "lit"
or
typename = "Form" and result = "frm"
or
typename = "Frame" and result = "fra"
or
typename = "CrystalReportViewer" and result = "crvr"
)
or
qualifier = "System.Web.UI.HtmlControls" and
(
typename = "TextArea" and result = "txa"
or
typename = "FileField" and result = "fle"
or
typename = "PasswordField" and result = "pwd"
or
typename = "Hidden" and result = "hdn"
or
typename = "Table" and result = "tbl"
or
typename = "FlowLayoutPanel" and result = "flp"
or
typename = "GridLayoutPanel" and result = "glp"
or
typename = "HorizontalRule" and result = "hr"
)
}
from Field f, RefType t, string name, string prefix, string qualifier, string type
where
f.getType() = t and
f.getName() = name and
t.hasFullyQualifiedName(qualifier, type) and
prefix = prefix(qualifier, type) and
not name.matches(prefix + "%")
select f, "This field should have the prefix '" + prefix + "' to match its types."