Skip to content

Commit 15a6044

Browse files
committed
Javascript: Autoformat qlls
1 parent fc9c7ea commit 15a6044

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+392
-270
lines changed

javascript/ql/src/semmle/javascript/AST.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ class JavaScriptURL extends @javascript_url, CodeInAttribute { }
212212
/**
213213
* A toplevel syntactic entity containing Closure-style externs definitions.
214214
*/
215-
class Externs extends TopLevel { Externs() { isExterns() } }
215+
class Externs extends TopLevel {
216+
Externs() { isExterns() }
217+
}
216218

217219
/** A program element that is either an expression or a statement. */
218220
class ExprOrStmt extends @exprorstmt, ControlFlowNode, ASTNode { }

javascript/ql/src/semmle/javascript/BasicBlocks.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,17 @@ class BasicBlock extends @cfg_node, Locatable {
284284
* An unreachable basic block, that is, a basic block
285285
* whose first node is unreachable.
286286
*/
287-
class UnreachableBlock extends BasicBlock { UnreachableBlock() { getFirstNode().isUnreachable() } }
287+
class UnreachableBlock extends BasicBlock {
288+
UnreachableBlock() { getFirstNode().isUnreachable() }
289+
}
288290

289291
/**
290292
* An entry basic block, that is, a basic block
291293
* whose first node is the entry node of a statement container.
292294
*/
293-
class EntryBasicBlock extends BasicBlock { EntryBasicBlock() { entryBB(this) } }
295+
class EntryBasicBlock extends BasicBlock {
296+
EntryBasicBlock() { entryBB(this) }
297+
}
294298

295299
/**
296300
* A basic block that is reachable from an entry basic block.

javascript/ql/src/semmle/javascript/Classes.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ class ClassExpr extends @classexpr, ClassDefinition, Expr {
227227
result = min(ClassInitializedMember m |
228228
m = getClassInitializedMember()
229229
|
230-
m
231-
order by
232-
m.getIndex()
230+
m order by m.getIndex()
233231
)
234232
else result = this
235233
}
@@ -287,7 +285,9 @@ class SuperPropAccess extends PropAccess {
287285
*
288286
* See also ECMAScript 2015 Language Specification, Chapter 12.3.8.
289287
*/
290-
class NewTargetExpr extends @newtargetexpr, Expr { override predicate isImpure() { none() } }
288+
class NewTargetExpr extends @newtargetexpr, Expr {
289+
override predicate isImpure() { none() }
290+
}
291291

292292
/**
293293
* A scope induced by a named class expression or class expression with type parameters.
@@ -432,12 +432,16 @@ class MemberDeclaration extends @property, Documentable {
432432
/**
433433
* A concrete member of a class, that is, a non-abstract, non-ambient field or method with a body.
434434
*/
435-
class MemberDefinition extends MemberDeclaration { MemberDefinition() { isConcrete() } }
435+
class MemberDefinition extends MemberDeclaration {
436+
MemberDefinition() { isConcrete() }
437+
}
436438

437439
/**
438440
* A member signature declared in a class or interface, that is, an abstract or ambient field or method without a function body.
439441
*/
440-
class MemberSignature extends MemberDeclaration { MemberSignature() { isSignature() } }
442+
class MemberSignature extends MemberDeclaration {
443+
MemberSignature() { isSignature() }
444+
}
441445

442446
/**
443447
* A method declaration in a class or interface, either a concrete definition or a signature without a body.

javascript/ql/src/semmle/javascript/Closure.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ module Closure {
3838
Expr getAnArgument() { result = getArgument(_) }
3939
}
4040

41-
abstract private class GoogNamespaceRef extends ExprOrStmt { abstract string getNamespaceId(); }
41+
abstract private class GoogNamespaceRef extends ExprOrStmt {
42+
abstract string getNamespaceId();
43+
}
4244

4345
/**
4446
* A call to `goog.provide`.

javascript/ql/src/semmle/javascript/Constants.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,6 @@ module SyntacticConstants {
123123
/**
124124
* An expression that evaluates to a constant string.
125125
*/
126-
class ConstantString extends ConstantExpr { ConstantString() { exists(getStringValue()) } }
126+
class ConstantString extends ConstantExpr {
127+
ConstantString() { exists(getStringValue()) }
128+
}

javascript/ql/src/semmle/javascript/DefUse.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,15 @@ class VarDef extends ControlFlowNode {
193193
* such as `for-in` loops, parameters or destructuring assignments.
194194
*/
195195
AST::ValueNode getSource() {
196-
exists(Expr target |
197-
not target instanceof DestructuringPattern and defn(this, target, result)
198-
)
196+
exists(Expr target | not target instanceof DestructuringPattern and defn(this, target, result))
199197
}
200198

201199
/**
202200
* Gets the source that this definition destructs, that is, the
203201
* right hand side of a destructuring assignment.
204202
*/
205203
AST::ValueNode getDestructuringSource() {
206-
exists(Expr target |
207-
target instanceof DestructuringPattern and defn(this, target, result)
208-
)
204+
exists(Expr target | target instanceof DestructuringPattern and defn(this, target, result))
209205
}
210206

211207
/**

javascript/ql/src/semmle/javascript/DefensiveProgramming.qll

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ module Internal {
199199
Expr target;
200200

201201
UndefinedNullCrashUse() {
202-
exists (Expr thrower |
203-
stripNotsAndParens(this, _) = thrower |
202+
exists(Expr thrower | stripNotsAndParens(this, _) = thrower |
204203
thrower.(InvokeExpr).getCallee().getUnderlyingValue() = target
205204
or
206205
thrower.(PropAccess).getBase().getUnderlyingValue() = target
@@ -224,7 +223,8 @@ module Internal {
224223
Expr target;
225224

226225
NonFunctionCallCrashUse() {
227-
stripNotsAndParens(this, _).(InvokeExpr).getCallee().getUnderlyingValue() = target }
226+
stripNotsAndParens(this, _).(InvokeExpr).getCallee().getUnderlyingValue() = target
227+
}
228228

229229
/**
230230
* Gets the subexpression that will cause an exception to be thrown if it is not a `function`.
@@ -276,9 +276,7 @@ module Internal {
276276
guardVar = stripNotsAndParens(this.asExpr(), polarity) and
277277
guardVar.getVariable() = useVar.getVariable()
278278
|
279-
getAGuardedExpr(this.asExpr())
280-
.(UndefinedNullCrashUse)
281-
.getVulnerableSubexpression() = useVar and
279+
getAGuardedExpr(this.asExpr()).(UndefinedNullCrashUse).getVulnerableSubexpression() = useVar and
282280
// exclude types whose truthiness depend on the value
283281
not isStringOrNumOrBool(guardVar.analyze().getAType())
284282
)
@@ -308,9 +306,7 @@ module Internal {
308306
test.getOperand() = guardVar and
309307
guardVar.getVariable() = useVar.getVariable()
310308
|
311-
getAGuardedExpr(guard)
312-
.(UndefinedNullCrashUse)
313-
.getVulnerableSubexpression() = useVar
309+
getAGuardedExpr(guard).(UndefinedNullCrashUse).getVulnerableSubexpression() = useVar
314310
)
315311
}
316312

@@ -376,9 +372,7 @@ module Internal {
376372
test.getOperand() = guardVar and
377373
guardVar.getVariable() = useVar.getVariable()
378374
|
379-
getAGuardedExpr(guard)
380-
.(NonFunctionCallCrashUse)
381-
.getVulnerableSubexpression() = useVar
375+
getAGuardedExpr(guard).(NonFunctionCallCrashUse).getVulnerableSubexpression() = useVar
382376
) and
383377
test.getTag() = "function"
384378
}

javascript/ql/src/semmle/javascript/ES2015Modules.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import javascript
66
* An ECMAScript 2015 module.
77
*/
88
class ES2015Module extends Module {
9-
ES2015Module() {
10-
isES2015Module(this)
11-
}
9+
ES2015Module() { isES2015Module(this) }
1210

1311
override ModuleScope getScope() { result.getScopeElement() = this }
1412

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ class Identifier extends @identifier, ExprOrType {
173173
* A statement or property label, that is, an identifier that
174174
* does not refer to a variable.
175175
*/
176-
class Label extends @label, Identifier, Expr { override predicate isImpure() { none() } }
176+
class Label extends @label, Identifier, Expr {
177+
override predicate isImpure() { none() }
178+
}
177179

178180
/** A literal. */
179181
class Literal extends @literal, Expr {
@@ -445,7 +447,9 @@ class PropertySetter extends PropertyAccessor, @property_setter { }
445447
* `{ x: 42, ...others }`. The value of a spread property is always
446448
* a `SpreadElement`.
447449
*/
448-
class SpreadProperty extends Property { SpreadProperty() { not exists(getNameExpr()) } }
450+
class SpreadProperty extends Property {
451+
SpreadProperty() { not exists(getNameExpr()) }
452+
}
449453

450454
/** A function expression. */
451455
class FunctionExpr extends @functionexpr, Expr, Function {
@@ -744,21 +748,29 @@ class NegExpr extends @negexpr, UnaryExpr {
744748
}
745749

746750
/** A unary plus expression. */
747-
class PlusExpr extends @plusexpr, UnaryExpr { override string getOperator() { result = "+" } }
751+
class PlusExpr extends @plusexpr, UnaryExpr {
752+
override string getOperator() { result = "+" }
753+
}
748754

749755
/** A logical negation expression. */
750-
class LogNotExpr extends @lognotexpr, UnaryExpr { override string getOperator() { result = "!" } }
756+
class LogNotExpr extends @lognotexpr, UnaryExpr {
757+
override string getOperator() { result = "!" }
758+
}
751759

752760
/** A bitwise negation expression. */
753-
class BitNotExpr extends @bitnotexpr, UnaryExpr { override string getOperator() { result = "~" } }
761+
class BitNotExpr extends @bitnotexpr, UnaryExpr {
762+
override string getOperator() { result = "~" }
763+
}
754764

755765
/** A `typeof` expression. */
756766
class TypeofExpr extends @typeofexpr, UnaryExpr {
757767
override string getOperator() { result = "typeof" }
758768
}
759769

760770
/** A `void` expression. */
761-
class VoidExpr extends @voidexpr, UnaryExpr { override string getOperator() { result = "void" } }
771+
class VoidExpr extends @voidexpr, UnaryExpr {
772+
override string getOperator() { result = "void" }
773+
}
762774

763775
/** A `delete` expression. */
764776
class DeleteExpr extends @deleteexpr, UnaryExpr {
@@ -839,10 +851,14 @@ class EqualityTest extends @equalitytest, Comparison {
839851
}
840852

841853
/** An equality test using `==`. */
842-
class EqExpr extends @eqexpr, EqualityTest { override string getOperator() { result = "==" } }
854+
class EqExpr extends @eqexpr, EqualityTest {
855+
override string getOperator() { result = "==" }
856+
}
843857

844858
/** An inequality test using `!=`. */
845-
class NEqExpr extends @neqexpr, EqualityTest { override string getOperator() { result = "!=" } }
859+
class NEqExpr extends @neqexpr, EqualityTest {
860+
override string getOperator() { result = "!=" }
861+
}
846862

847863
/** A strict equality test using `===`. */
848864
class StrictEqExpr extends @eqqexpr, EqualityTest {
@@ -855,22 +871,34 @@ class StrictNEqExpr extends @neqqexpr, EqualityTest {
855871
}
856872

857873
/** A less-than expression. */
858-
class LTExpr extends @ltexpr, Comparison { override string getOperator() { result = "<" } }
874+
class LTExpr extends @ltexpr, Comparison {
875+
override string getOperator() { result = "<" }
876+
}
859877

860878
/** A less-than-or-equal expression. */
861-
class LEExpr extends @leexpr, Comparison { override string getOperator() { result = "<=" } }
879+
class LEExpr extends @leexpr, Comparison {
880+
override string getOperator() { result = "<=" }
881+
}
862882

863883
/** A greater-than expression. */
864-
class GTExpr extends @gtexpr, Comparison { override string getOperator() { result = ">" } }
884+
class GTExpr extends @gtexpr, Comparison {
885+
override string getOperator() { result = ">" }
886+
}
865887

866888
/** A greater-than-or-equal expression. */
867-
class GEExpr extends @geexpr, Comparison { override string getOperator() { result = ">=" } }
889+
class GEExpr extends @geexpr, Comparison {
890+
override string getOperator() { result = ">=" }
891+
}
868892

869893
/** A left-shift expression using `<<`. */
870-
class LShiftExpr extends @lshiftexpr, BinaryExpr { override string getOperator() { result = "<<" } }
894+
class LShiftExpr extends @lshiftexpr, BinaryExpr {
895+
override string getOperator() { result = "<<" }
896+
}
871897

872898
/** A right-shift expression using `>>`. */
873-
class RShiftExpr extends @rshiftexpr, BinaryExpr { override string getOperator() { result = ">>" } }
899+
class RShiftExpr extends @rshiftexpr, BinaryExpr {
900+
override string getOperator() { result = ">>" }
901+
}
874902

875903
/** An unsigned right-shift expression using `>>>`. */
876904
class URShiftExpr extends @urshiftexpr, BinaryExpr {
@@ -887,31 +915,49 @@ class AddExpr extends @addexpr, BinaryExpr {
887915
}
888916

889917
/** A subtraction expression. */
890-
class SubExpr extends @subexpr, BinaryExpr { override string getOperator() { result = "-" } }
918+
class SubExpr extends @subexpr, BinaryExpr {
919+
override string getOperator() { result = "-" }
920+
}
891921

892922
/** A multiplication expression. */
893-
class MulExpr extends @mulexpr, BinaryExpr { override string getOperator() { result = "*" } }
923+
class MulExpr extends @mulexpr, BinaryExpr {
924+
override string getOperator() { result = "*" }
925+
}
894926

895927
/** A division expression. */
896-
class DivExpr extends @divexpr, BinaryExpr { override string getOperator() { result = "/" } }
928+
class DivExpr extends @divexpr, BinaryExpr {
929+
override string getOperator() { result = "/" }
930+
}
897931

898932
/** A modulo expression. */
899-
class ModExpr extends @modexpr, BinaryExpr { override string getOperator() { result = "%" } }
933+
class ModExpr extends @modexpr, BinaryExpr {
934+
override string getOperator() { result = "%" }
935+
}
900936

901937
/** An exponentiation expression. */
902-
class ExpExpr extends @expexpr, BinaryExpr { override string getOperator() { result = "**" } }
938+
class ExpExpr extends @expexpr, BinaryExpr {
939+
override string getOperator() { result = "**" }
940+
}
903941

904942
/** A bitwise 'or' expression. */
905-
class BitOrExpr extends @bitorexpr, BinaryExpr { override string getOperator() { result = "|" } }
943+
class BitOrExpr extends @bitorexpr, BinaryExpr {
944+
override string getOperator() { result = "|" }
945+
}
906946

907947
/** An exclusive 'or' expression. */
908-
class XOrExpr extends @xorexpr, BinaryExpr { override string getOperator() { result = "^" } }
948+
class XOrExpr extends @xorexpr, BinaryExpr {
949+
override string getOperator() { result = "^" }
950+
}
909951

910952
/** A bitwise 'and' expression. */
911-
class BitAndExpr extends @bitandexpr, BinaryExpr { override string getOperator() { result = "&" } }
953+
class BitAndExpr extends @bitandexpr, BinaryExpr {
954+
override string getOperator() { result = "&" }
955+
}
912956

913957
/** An `in` expression. */
914-
class InExpr extends @inexpr, BinaryExpr { override string getOperator() { result = "in" } }
958+
class InExpr extends @inexpr, BinaryExpr {
959+
override string getOperator() { result = "in" }
960+
}
915961

916962
/** An `instanceof` expression. */
917963
class InstanceofExpr extends @instanceofexpr, BinaryExpr {
@@ -1359,7 +1405,9 @@ class AwaitExpr extends @awaitexpr, Expr {
13591405
* to the generator by the `next` method that most recently resumed execution
13601406
* of the generator.
13611407
*/
1362-
class FunctionSentExpr extends @functionsentexpr, Expr { override predicate isImpure() { none() } }
1408+
class FunctionSentExpr extends @functionsentexpr, Expr {
1409+
override predicate isImpure() { none() }
1410+
}
13631411

13641412
/**
13651413
* A decorator applied to a class, property or member definition.
@@ -1468,7 +1516,9 @@ private class LiteralDynamicImportPath extends PathExprInModule, ConstantString
14681516
/**
14691517
* A call or member access that evaluates to `undefined` if its base operand evaluates to `undefined` or `null`.
14701518
*/
1471-
class OptionalUse extends Expr, @optionalchainable { OptionalUse() { isOptionalChaining(this) } }
1519+
class OptionalUse extends Expr, @optionalchainable {
1520+
OptionalUse() { isOptionalChaining(this) }
1521+
}
14721522

14731523
private class ChainElem extends Expr, @optionalchainable {
14741524
/**

0 commit comments

Comments
 (0)