Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 43309b9

Browse files
authored
Merge pull request #93 from max-schaefer/autoformat
Autoformat QL and Go
2 parents 96ee5f1 + 1fe5e7f commit 43309b9

23 files changed

Lines changed: 81 additions & 139 deletions

File tree

ql/src/AlertSuppression.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import go
1212
*/
1313
class SuppressionComment extends Locatable {
1414
string text;
15-
1615
string annotation;
1716

1817
SuppressionComment() {

ql/src/RedundantCode/DeadStoreOfField.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ predicate escapes(DataFlow::Node nd) {
5858
* the embedded field has the pointer type `*T` or just type `T`.
5959
*/
6060
Type getEmbeddedType(Type t, boolean isPtr) {
61-
exists(Type embedded |
62-
t.getUnderlyingType().(StructType).hasOwnField(_, _, embedded, true) |
63-
if embedded instanceof PointerType then (
61+
exists(Type embedded | t.getUnderlyingType().(StructType).hasOwnField(_, _, embedded, true) |
62+
if embedded instanceof PointerType
63+
then (
6464
result = embedded.(PointerType).getBaseType() and
6565
isPtr = true
6666
) else (
@@ -71,9 +71,7 @@ Type getEmbeddedType(Type t, boolean isPtr) {
7171
}
7272

7373
/** Gets an embedded type of `t`. */
74-
Type getEmbeddedType(Type t) {
75-
result = getEmbeddedType(t, _)
76-
}
74+
Type getEmbeddedType(Type t) { result = getEmbeddedType(t, _) }
7775

7876
/**
7977
* Gets a transitive embedded type of `t`, where at least one of the embeddings goes through a

ql/src/RedundantCode/ExprHasNoEffect.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ predicate inVoidContext(Expr e) {
2626
/**
2727
* Holds if `ce` is a call to a stub function with an empty body.
2828
*/
29-
predicate callToStubFunction(CallExpr ce) {
30-
ce.getTarget().getBody().getNumStmt() = 0
31-
}
29+
predicate callToStubFunction(CallExpr ce) { ce.getTarget().getBody().getNumStmt() = 0 }
3230

3331
from Expr e
3432
where

ql/src/Security/CWE-020/MissingRegexpAnchor.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ predicate isInterestingSemiAnchoredRegexpString(string re, string msg) {
3838
) and
3939
anchorPart = re.regexpCapture(regex, 1) and
4040
anchorPart.regexpMatch("(?i).*[a-z].*") and
41-
msg = "Misleading operator precedence. The subexpression '" + anchorPart +
41+
msg =
42+
"Misleading operator precedence. The subexpression '" + anchorPart +
4243
"' is anchored, but the other parts of this regular expression are not."
4344
)
4445
}
@@ -53,7 +54,9 @@ predicate isInterestingUnanchoredRegexpString(string re, string msg) {
5354
re.regexpMatch("(?i)[():|?a-z0-9-\\\\./]+[.]" + commonTLD() + "([/#?():]\\S*)?") and
5455
// without any anchors
5556
re.regexpMatch("[^$^]+") and
56-
msg = "When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it."
57+
msg =
58+
"When this is used as a regular expression on a URL, it may match anywhere, and arbitrary " +
59+
"hosts may come before or after it."
5760
}
5861

5962
class Config extends DataFlow::Configuration {

ql/src/Security/CWE-190/AllocationSizeOverflow.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ where
2121
cfg.hasFlowPath(source, sink) and
2222
cfg.isSink(sink.getNode(), allocsz)
2323
select sink, source, sink,
24-
"This operation, which is used in an $@, involves a potentially large $@ " +
25-
"and might overflow.", allocsz, "allocation", source, "value"
24+
"This operation, which is used in an $@, involves a potentially large $@ " + "and might overflow.",
25+
allocsz, "allocation", source, "value"

ql/src/semmle/go/Comments.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ private predicate isInitialComment(Comment c, File f, int line, int col) {
8686

8787
/** Gets the `i`th initial comment in `f` (0-based). */
8888
private Comment getInitialComment(File f, int i) {
89-
result = rank[i + 1](Comment c, int line, int col |
89+
result =
90+
rank[i + 1](Comment c, int line, int col |
9091
isInitialComment(c, f, line, col)
9192
|
9293
c order by line, col

ql/src/semmle/go/Decls.qll

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,47 +101,38 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
101101

102102
/** Gets the `i`th result variable of this function. */
103103
ResultVariable getResultVar(int i) {
104-
result = rank[i + 1](ResultVariable res, int j, int k |
104+
result =
105+
rank[i + 1](ResultVariable res, int j, int k |
105106
res.getDeclaration() = getTypeExpr().getResultDecl(j).getNameExpr(k)
106107
|
107108
res order by j, k
108109
)
109110
}
110111

111112
/** Gets a result variable of this function. */
112-
ResultVariable getAResultVar() {
113-
result.getFunction() = this
114-
}
113+
ResultVariable getAResultVar() { result.getFunction() = this }
115114

116115
/**
117116
* Gets the `i`th parameter of this function.
118117
*
119118
* The receiver variable, if any, is considered to be the -1st parameter.
120119
*/
121-
Parameter getParameter(int i) {
122-
result.isParameterOf(this, i)
123-
}
120+
Parameter getParameter(int i) { result.isParameterOf(this, i) }
124121

125122
/**
126123
* Gets a parameter of this function.
127124
*/
128-
Parameter getAParameter() {
129-
result.getFunction() = this
130-
}
125+
Parameter getAParameter() { result.getFunction() = this }
131126

132127
/**
133128
* Gets the number of parameters of this function.
134129
*/
135-
int getNumParameter() {
136-
result = count(getAParameter())
137-
}
130+
int getNumParameter() { result = count(getAParameter()) }
138131

139132
/**
140133
* Gets a call to this function.
141134
*/
142-
DataFlow::CallNode getACall() {
143-
result.getACallee() = this
144-
}
135+
DataFlow::CallNode getACall() { result.getACallee() = this }
145136
}
146137

147138
/**
@@ -526,9 +517,7 @@ class ResultVariableDecl extends @field, Documentable, ExprParent {
526517
/**
527518
* Gets an expression representing the name of a result variable declared in this declaration.
528519
*/
529-
Expr getANameExpr() {
530-
result = getNameExpr(_)
531-
}
520+
Expr getANameExpr() { result = getNameExpr(_) }
532521

533522
/**
534523
* Gets the function type expression to which this result variable declaration belongs.
@@ -549,7 +538,6 @@ class ResultVariableDecl extends @field, Documentable, ExprParent {
549538
*/
550539
class InterfaceMemberSpec extends @field, Documentable, ExprParent {
551540
InterfaceTypeExpr ite;
552-
553541
int idx;
554542

555543
InterfaceMemberSpec() { fields(this, ite, idx) }

ql/src/semmle/go/Scopes.qll

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,12 @@ class Parameter extends DeclaredVariable {
239239
index = -1
240240
or
241241
exists(FuncTypeExpr tp | tp = f.getTypeExpr() |
242-
this = rank[index + 1](DeclaredVariable parm, int j, int k |
243-
parm.getDeclaration() = tp.getParameterDecl(j).getNameExpr(k)
244-
|
245-
parm order by j, k
246-
)
242+
this =
243+
rank[index + 1](DeclaredVariable parm, int j, int k |
244+
parm.getDeclaration() = tp.getParameterDecl(j).getNameExpr(k)
245+
|
246+
parm order by j, k
247+
)
247248
)
248249
}
249250

@@ -258,9 +259,7 @@ class Parameter extends DeclaredVariable {
258259
int getIndex() { result = index }
259260

260261
/** Holds if this is the `i`th parameter of function `fd`. */
261-
predicate isParameterOf(FuncDef fd, int i) {
262-
fd = f and i = index
263-
}
262+
predicate isParameterOf(FuncDef fd, int i) { fd = f and i = index }
264263
}
265264

266265
/** The receiver variable of a method. */
@@ -310,9 +309,7 @@ class Field extends Variable {
310309
StructType getDeclaringType() { result = declaringType }
311310

312311
override Package getPackage() {
313-
exists(Type tp | tp.getUnderlyingType() = declaringType |
314-
result = tp.getPackage()
315-
)
312+
exists(Type tp | tp.getUnderlyingType() = declaringType | result = tp.getPackage())
316313
}
317314

318315
/**

ql/src/semmle/go/Types.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ class StructType extends @structtype, CompositeType {
430430

431431
language[monotonicAggregates]
432432
override string pp() {
433-
result = "struct { " +
433+
result =
434+
"struct { " +
434435
concat(int i, string name, Type tp |
435436
component_types(this, i, name, tp)
436437
|
@@ -488,7 +489,8 @@ class InterfaceType extends @interfacetype, CompositeType {
488489

489490
language[monotonicAggregates]
490491
override string pp() {
491-
result = "interface { " +
492+
result =
493+
"interface { " +
492494
concat(string name, Type tp |
493495
tp = getMethodType(name)
494496
|
@@ -506,8 +508,8 @@ class TupleType extends @tupletype, CompositeType {
506508

507509
language[monotonicAggregates]
508510
override string pp() {
509-
result = "(" + concat(int i, Type tp | tp = getComponentType(i) | tp.pp(), ", " order by i) +
510-
")"
511+
result =
512+
"(" + concat(int i, Type tp | tp = getComponentType(i) | tp.pp(), ", " order by i) + ")"
511513
}
512514

513515
override string toString() { result = "tuple type" }
@@ -529,8 +531,9 @@ class SignatureType extends @signaturetype, CompositeType {
529531

530532
language[monotonicAggregates]
531533
override string pp() {
532-
result = "func(" + concat(int i, Type tp | tp = getParameterType(i) | tp.pp(), ", " order by i) +
533-
") " + concat(int i, Type tp | tp = getResultType(i) | tp.pp(), ", " order by i)
534+
result =
535+
"func(" + concat(int i, Type tp | tp = getParameterType(i) | tp.pp(), ", " order by i) + ") " +
536+
concat(int i, Type tp | tp = getResultType(i) | tp.pp(), ", " order by i)
534537
}
535538

536539
override string toString() { result = "signature type" }

ql/src/semmle/go/controlflow/BasicBlocks.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private module Internal {
6262
exists(BasicBlock predBB | succBB(predBB, bb) | reachableBB(predBB))
6363
}
6464
}
65+
6566
private import Internal
6667

6768
/** Holds if `dom` is an immediate dominator of `bb`. */

0 commit comments

Comments
 (0)