Skip to content

Commit 201f68d

Browse files
authored
Merge pull request #757 from hvitved/csharp/autoformat/queries
Approved by calumgrant
2 parents 955bad0 + 36e4b87 commit 201f68d

37 files changed

+141
-181
lines changed

csharp/ql/src/API Abuse/ClassDoesNotImplementEquals.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ where
2828
itemText = "here"
2929
)
3030
or
31-
(
32-
item = c.getAnOperator().(EQOperator) and
33-
message = "but it implements $@" and
34-
itemText = "operator =="
35-
)
31+
item = c.getAnOperator().(EQOperator) and
32+
message = "but it implements $@" and
33+
itemText = "operator =="
3634
or
3735
exists(IEquatableEqualsMethod eq |
3836
item = eq and

csharp/ql/src/API Abuse/InconsistentEqualsGetHashCode.ql

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ from Class c, Method present, string missing
1818
where
1919
c.isSourceDeclaration() and
2020
(
21-
(
22-
present = c.getAMethod().(EqualsMethod) and
23-
not c.getAMethod() instanceof GetHashCodeMethod and
24-
missing = "GetHashCode()"
25-
)
21+
present = c.getAMethod().(EqualsMethod) and
22+
not c.getAMethod() instanceof GetHashCodeMethod and
23+
missing = "GetHashCode()"
2624
or
27-
(
28-
present = c.getAMethod().(GetHashCodeMethod) and
29-
not implementsEquals(c) and
30-
missing = "Equals(object)"
31-
)
25+
present = c.getAMethod().(GetHashCodeMethod) and
26+
not implementsEquals(c) and
27+
missing = "Equals(object)"
3228
)
3329
select c, "Class '" + c.getName() + "' overrides $@, but not " + missing + ".", present,
3430
present.getName()

csharp/ql/src/API Abuse/IncorrectCompareToSignature.ql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ predicate implementsIComparable(ValueOrRefType t, Type paramType) {
2020
or
2121
t instanceof SystemIComparableTInterface
2222
or
23-
(
24-
t.getABaseType*() instanceof SystemIComparableInterface and
25-
paramType instanceof ObjectType
26-
)
23+
t.getABaseType*() instanceof SystemIComparableInterface and
24+
paramType instanceof ObjectType
2725
}
2826

2927
predicate compareToMethod(Method m, Type paramType) {

csharp/ql/src/API Abuse/UncheckedReturnValue.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DiscardedMethodCall extends MethodCall {
9999
// to deliberately ignore the returned value
100100
not getEnclosingCallable().getStatementBody().getNumberOfStmts() = 1
101101
|
102-
(important(m) and result = "should always be checked")
102+
important(m) and result = "should always be checked"
103103
or
104104
exists(int percentage | dubious(m, percentage) |
105105
result = percentage.toString() + "% of calls to this method have their result used"

csharp/ql/src/Bad Practices/Naming Conventions/ConstantNaming.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class PublicConstantField extends Field {
2323
from PublicConstantField f
2424
where
2525
// The first character of the field's name is not uppercase.
26-
not (f.getName().charAt(0).isUppercase())
26+
not f.getName().charAt(0).isUppercase()
2727
or
28-
(
29-
// The field's name is uppercase.
30-
f.getName().isUppercase() and
31-
// The field's name is at least 4 characters long.
32-
f.getName().length() >= 4
33-
)
28+
// The field's name is uppercase.
29+
f.getName().isUppercase() and
30+
// The field's name is at least 4 characters long.
31+
f.getName().length() >= 4
3432
select f, "Public static read-only fields should be named in PascalCase."

csharp/ql/src/Bad Practices/Naming Conventions/ControlNamePrefixes.ql

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,83 @@
1212
import csharp
1313

1414
string prefix(string typename) {
15-
(typename = "System.Web.UI.WebControls.Label" and result = "lbl")
15+
typename = "System.Web.UI.WebControls.Label" and result = "lbl"
1616
or
17-
(typename = "System.Web.UI.WebControls.TextBox" and result = "txt")
17+
typename = "System.Web.UI.WebControls.TextBox" and result = "txt"
1818
or
19-
(typename = "System.Web.UI.WebControls.Button" and result = "btn")
19+
typename = "System.Web.UI.WebControls.Button" and result = "btn"
2020
or
21-
(typename = "System.Web.UI.WebControls.LinkButton" and result = "btn")
21+
typename = "System.Web.UI.WebControls.LinkButton" and result = "btn"
2222
or
23-
(typename = "System.Web.UI.WebControls.ImageButton" and result = "ibtn")
23+
typename = "System.Web.UI.WebControls.ImageButton" and result = "ibtn"
2424
or
25-
(typename = "System.Web.UI.WebControls.Hyperlink" and result = "hpl")
25+
typename = "System.Web.UI.WebControls.Hyperlink" and result = "hpl"
2626
or
27-
(typename = "System.Web.UI.WebControls.DropDownList" and result = "cmb")
27+
typename = "System.Web.UI.WebControls.DropDownList" and result = "cmb"
2828
or
29-
(typename = "System.Web.UI.WebControls.ListBox" and result = "lst")
29+
typename = "System.Web.UI.WebControls.ListBox" and result = "lst"
3030
or
31-
(typename = "System.Web.UI.WebControls.Datagrid" and result = "dgr")
31+
typename = "System.Web.UI.WebControls.Datagrid" and result = "dgr"
3232
or
33-
(typename = "System.Web.UI.WebControls.Datalist" and result = "dtl")
33+
typename = "System.Web.UI.WebControls.Datalist" and result = "dtl"
3434
or
35-
(typename = "System.Web.UI.WebControls.Repeater" and result = "rpt")
35+
typename = "System.Web.UI.WebControls.Repeater" and result = "rpt"
3636
or
37-
(typename = "System.Web.UI.WebControls.CheckBox" and result = "chk")
37+
typename = "System.Web.UI.WebControls.CheckBox" and result = "chk"
3838
or
39-
(typename = "System.Web.UI.WebControls.CheckBoxList" and result = "chklst")
39+
typename = "System.Web.UI.WebControls.CheckBoxList" and result = "chklst"
4040
or
41-
(typename = "System.Web.UI.WebControls.RadioButtonList" and result = "radlst")
41+
typename = "System.Web.UI.WebControls.RadioButtonList" and result = "radlst"
4242
or
43-
(typename = "System.Web.UI.WebControls.RadioButton" and result = "rad")
43+
typename = "System.Web.UI.WebControls.RadioButton" and result = "rad"
4444
or
45-
(typename = "System.Web.UI.WebControls.Image" and result = "img")
45+
typename = "System.Web.UI.WebControls.Image" and result = "img"
4646
or
47-
(typename = "System.Web.UI.WebControls.Panel" and result = "pnl")
47+
typename = "System.Web.UI.WebControls.Panel" and result = "pnl"
4848
or
49-
(typename = "System.Web.UI.WebControls.PlaceHolder" and result = "plh")
49+
typename = "System.Web.UI.WebControls.PlaceHolder" and result = "plh"
5050
or
51-
(typename = "System.Web.UI.WebControls.Calendar" and result = "cal")
51+
typename = "System.Web.UI.WebControls.Calendar" and result = "cal"
5252
or
53-
(typename = "System.Web.UI.WebControls.AdRotator" and result = "adr")
53+
typename = "System.Web.UI.WebControls.AdRotator" and result = "adr"
5454
or
55-
(typename = "System.Web.UI.WebControls.Table" and result = "tbl")
55+
typename = "System.Web.UI.WebControls.Table" and result = "tbl"
5656
or
57-
(typename = "System.Web.UI.WebControls.RequiredFieldValidator" and result = "rfv")
57+
typename = "System.Web.UI.WebControls.RequiredFieldValidator" and result = "rfv"
5858
or
59-
(typename = "System.Web.UI.WebControls.CompareValidator" and result = "cmv")
59+
typename = "System.Web.UI.WebControls.CompareValidator" and result = "cmv"
6060
or
61-
(typename = "System.Web.UI.WebControls.RegularExpressionValidator" and result = "rev")
61+
typename = "System.Web.UI.WebControls.RegularExpressionValidator" and result = "rev"
6262
or
63-
(typename = "System.Web.UI.WebControls.CustomValidator" and result = "csv")
63+
typename = "System.Web.UI.WebControls.CustomValidator" and result = "csv"
6464
or
65-
(typename = "System.Web.UI.WebControls.ValidationSummary" and result = "vsm")
65+
typename = "System.Web.UI.WebControls.ValidationSummary" and result = "vsm"
6666
or
67-
(typename = "System.Web.UI.WebControls.XML" and result = "xml")
67+
typename = "System.Web.UI.WebControls.XML" and result = "xml"
6868
or
69-
(typename = "System.Web.UI.WebControls.Literal" and result = "lit")
69+
typename = "System.Web.UI.WebControls.Literal" and result = "lit"
7070
or
71-
(typename = "System.Web.UI.WebControls.Form" and result = "frm")
71+
typename = "System.Web.UI.WebControls.Form" and result = "frm"
7272
or
73-
(typename = "System.Web.UI.WebControls.Frame" and result = "fra")
73+
typename = "System.Web.UI.WebControls.Frame" and result = "fra"
7474
or
75-
(typename = "System.Web.UI.WebControls.CrystalReportViewer" and result = "crvr")
75+
typename = "System.Web.UI.WebControls.CrystalReportViewer" and result = "crvr"
7676
or
77-
(typename = "System.Web.UI.HtmlControls.TextArea" and result = "txa")
77+
typename = "System.Web.UI.HtmlControls.TextArea" and result = "txa"
7878
or
79-
(typename = "System.Web.UI.HtmlControls.FileField" and result = "fle")
79+
typename = "System.Web.UI.HtmlControls.FileField" and result = "fle"
8080
or
81-
(typename = "System.Web.UI.HtmlControls.PasswordField" and result = "pwd")
81+
typename = "System.Web.UI.HtmlControls.PasswordField" and result = "pwd"
8282
or
83-
(typename = "System.Web.UI.HtmlControls.Hidden" and result = "hdn")
83+
typename = "System.Web.UI.HtmlControls.Hidden" and result = "hdn"
8484
or
85-
(typename = "System.Web.UI.HtmlControls.Table" and result = "tbl")
85+
typename = "System.Web.UI.HtmlControls.Table" and result = "tbl"
8686
or
87-
(typename = "System.Web.UI.HtmlControls.FlowLayoutPanel" and result = "flp")
87+
typename = "System.Web.UI.HtmlControls.FlowLayoutPanel" and result = "flp"
8888
or
89-
(typename = "System.Web.UI.HtmlControls.GridLayoutPanel" and result = "glp")
89+
typename = "System.Web.UI.HtmlControls.GridLayoutPanel" and result = "glp"
9090
or
91-
(typename = "System.Web.UI.HtmlControls.HorizontalRule" and result = "hr")
91+
typename = "System.Web.UI.HtmlControls.HorizontalRule" and result = "hr"
9292
}
9393

9494
from Field f, RefType t, string name, string prefix

csharp/ql/src/Complexity/ComplexCondition.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ predicate logicalParent(LogicalOperation op, LogicalOperation parent) { parent =
2222

2323
from Expr e, int operators
2424
where
25-
not (e.getParent() instanceof LogicalOperation) and
25+
not e.getParent() instanceof LogicalOperation and
2626
operators = count(BinaryLogicalOperation op |
2727
logicalParent*(op, e) and nontrivialLogicalOperator(op)
2828
) and

csharp/ql/src/Concurrency/LockedWait.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ where
2929
lockedItem = "typeof(" + t.getName() + ")"
3030
)
3131
or
32-
(l.isLockThis() and not w.isWaitThis() and lockedItem = "this")
32+
l.isLockThis() and not w.isWaitThis() and lockedItem = "this"
3333
)
3434
select w, "'" + lockedItem + "' is locked during this wait."

csharp/ql/src/Dead Code/NonAssignedFields.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ where
8787
not exists(Assignment ae, Field g |
8888
ae.getLValue().(FieldAccess).getTarget() = g and
8989
g.getSourceDeclaration() = f and
90-
not (ae.getRValue() instanceof NullLiteral)
90+
not ae.getRValue() instanceof NullLiteral
9191
) and
9292
not exists(MethodCall mc, int i, Field g |
9393
exists(Parameter p | mc.getTarget().getParameter(i) = p | p.isOut() or p.isRef()) and

csharp/ql/src/Language Abuse/MissedTernaryOpportunity.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class StructuralComparisonConfig extends StructuralComparisonConfiguration {
3636
from IfStmt is, string what
3737
where
3838
(
39-
(
40-
is.getThen().stripSingletonBlocks() instanceof ReturnStmt and
41-
is.getElse().stripSingletonBlocks() instanceof ReturnStmt and
42-
what = "return"
43-
)
39+
is.getThen().stripSingletonBlocks() instanceof ReturnStmt and
40+
is.getElse().stripSingletonBlocks() instanceof ReturnStmt and
41+
what = "return"
4442
or
4543
exists(StructuralComparisonConfig c |
4644
is = c.getIfStmt() and

0 commit comments

Comments
 (0)