Skip to content

Commit d8c9dba

Browse files
committed
JS: Autoformat
1 parent 5f4016b commit d8c9dba

File tree

7 files changed

+68
-85
lines changed

7 files changed

+68
-85
lines changed

javascript/ql/src/DOM/TargetBlank.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import semmle.javascript.RestrictedLocations
2020
* Holds if the `rel` attribute may be injected by an Angular2 directive.
2121
*/
2222
predicate maybeInjectedByAngular() {
23-
DataFlow::moduleMember("@angular/core", "HostBinding").getACall().getArgument(0).mayHaveStringValue("attr.rel")
23+
DataFlow::moduleMember("@angular/core", "HostBinding")
24+
.getACall()
25+
.getArgument(0)
26+
.mayHaveStringValue("attr.rel")
2427
}
2528

2629
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ class InlineScript extends @inline_script, Script { }
300300
* ```
301301
*/
302302
class CodeInAttribute extends TopLevel {
303-
CodeInAttribute() { this instanceof @event_handler or this instanceof @javascript_url or this instanceof @angular_template_toplevel }
303+
CodeInAttribute() {
304+
this instanceof @event_handler or
305+
this instanceof @javascript_url or
306+
this instanceof @angular_template_toplevel
307+
}
304308
}
305309

306310
/**

javascript/ql/src/semmle/javascript/HTML.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ module HTML {
2929
}
3030

3131
/** Gets `i`th root node of the HTML fragment embedded in the given expression, if any. */
32-
Element getHtmlElementFromExpr(Expr e, int i) {
33-
xml_element_parent_expression(result, e, i)
34-
}
32+
Element getHtmlElementFromExpr(Expr e, int i) { xml_element_parent_expression(result, e, i) }
3533

3634
/**
3735
* An HTML element.
@@ -127,9 +125,7 @@ module HTML {
127125
/**
128126
* Gets the inline script of this attribute, if any.
129127
*/
130-
CodeInAttribute getCodeInAttribute() {
131-
toplevel_parent_xml_node(result, this)
132-
}
128+
CodeInAttribute getCodeInAttribute() { toplevel_parent_xml_node(result, this) }
133129

134130
/**
135131
* Gets the element to which this attribute belongs.

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,7 @@ module DataFlow {
13201320
* Certain framework models may need this node to model the behavior of
13211321
* class and field decorators.
13221322
*/
1323-
DataFlow::Node fieldDeclarationNode(FieldDeclaration field) {
1324-
result = TPropNode(field)
1325-
}
1323+
DataFlow::Node fieldDeclarationNode(FieldDeclaration field) { result = TPropNode(field) }
13261324

13271325
/**
13281326
* Gets the data flow node corresponding the given l-value expression, if

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,7 @@ class ClassNode extends DataFlow::SourceNode {
10111011
/**
10121012
* Gets a decorator applied to this class.
10131013
*/
1014-
DataFlow::Node getADecorator() {
1015-
result = impl.getADecorator()
1016-
}
1014+
DataFlow::Node getADecorator() { result = impl.getADecorator() }
10171015
}
10181016

10191017
module ClassNode {

javascript/ql/src/semmle/javascript/frameworks/Angular2.qll

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,12 @@ module Angular2 {
233233
*/
234234
class PipeRefExpr extends Expr, @angular_pipe_ref {
235235
/** Gets the identifier node naming the pipe. */
236-
Identifier getIdentifier() {
237-
result = getChildExpr(0)
238-
}
236+
Identifier getIdentifier() { result = getChildExpr(0) }
239237

240238
/** Gets the name of the pipe being referenced. */
241239
string getName() { result = getIdentifier().getName() }
242240

243-
override string getAPrimaryQlClass() {
244-
result = "Angular2::PipeRefExpr"
245-
}
241+
override string getAPrimaryQlClass() { result = "Angular2::PipeRefExpr" }
246242
}
247243

248244
/**
@@ -252,32 +248,24 @@ module Angular2 {
252248
* `f` is a `PipeRefExpr` and the call itself is a `PipeCallExpr`.
253249
*/
254250
class PipeCallExpr extends CallExpr {
255-
PipeCallExpr() {
256-
getCallee() instanceof PipeRefExpr
257-
}
251+
PipeCallExpr() { getCallee() instanceof PipeRefExpr }
258252

259253
/** Gets the name of the pipe being invoked, such as `f` in `x | f`. */
260-
string getPipeName() {
261-
result = getCallee().(PipeRefExpr).getName()
262-
}
254+
string getPipeName() { result = getCallee().(PipeRefExpr).getName() }
263255
}
264256

265257
/**
266258
* A reference to a variable in a template expression, corresponding
267259
* to a property on the component class.
268260
*/
269261
class TemplateVarRefExpr extends Expr {
270-
TemplateVarRefExpr() {
271-
this = any(TemplateTopLevel tl).getScope().getAVariable().getAnAccess()
272-
}
262+
TemplateVarRefExpr() { this = any(TemplateTopLevel tl).getScope().getAVariable().getAnAccess() }
273263
}
274264

275265
/** The top-level containing an Angular expression. */
276266
class TemplateTopLevel extends TopLevel, @angular_template_toplevel {
277267
/** Gets the expression in this top-level. */
278-
Expr getExpression() {
279-
result = getChildStmt(0).(ExprStmt).getExpr()
280-
}
268+
Expr getExpression() { result = getChildStmt(0).(ExprStmt).getExpr() }
281269

282270
/** Gets the data flow node representing the initialization of the given variable in this scope. */
283271
DataFlow::Node getVariableInit(string name) {
@@ -299,9 +287,7 @@ module Angular2 {
299287
)
300288
}
301289

302-
override string getValue() {
303-
result = this.(Expr).getStringValue()
304-
}
290+
override string getValue() { result = this.(Expr).getStringValue() }
305291
}
306292

307293
/**
@@ -365,18 +351,15 @@ module Angular2 {
365351
/**
366352
* Gets the `selector` property of the `@Component` decorator.
367353
*/
368-
string getSelector() {
369-
decorator.getOptionArgument(0, "selector").mayHaveStringValue(result)
370-
}
354+
string getSelector() { decorator.getOptionArgument(0, "selector").mayHaveStringValue(result) }
371355

372356
/** Gets an HTML element that instantiates this component. */
373-
HTML::Element getATemplateInstantiation() {
374-
result.getName() = getSelector()
375-
}
357+
HTML::Element getATemplateInstantiation() { result.getName() = getSelector() }
376358

377359
/** Gets an argument that flows into the `name` field of this component. */
378360
DataFlow::Node getATemplateArgument(string name) {
379-
result = getAttributeValueAsNode(getATemplateInstantiation().getAttributeByName("[" + name + "]"))
361+
result =
362+
getAttributeValueAsNode(getATemplateInstantiation().getAttributeByName("[" + name + "]"))
380363
}
381364

382365
/**
@@ -393,14 +376,20 @@ module Angular2 {
393376
HTML::Element getATemplateElement() {
394377
result.getFile() = getTemplateFile()
395378
or
396-
result.getParent*() = HTML::getHtmlElementFromExpr(decorator.getOptionArgument(0, "template").asExpr(), _)
379+
result.getParent*() =
380+
HTML::getHtmlElementFromExpr(decorator.getOptionArgument(0, "template").asExpr(), _)
397381
}
398382

399383
/**
400384
* Gets an access to the given template variable within the template body of this component.
401385
*/
402386
DataFlow::SourceNode getATemplateVarAccess(string name) {
403-
result = getATemplateElement().getAnAttribute().getCodeInAttribute().(TemplateTopLevel).getAVariableUse(name)
387+
result =
388+
getATemplateElement()
389+
.getAnAttribute()
390+
.getCodeInAttribute()
391+
.(TemplateTopLevel)
392+
.getAVariableUse(name)
404393
}
405394
}
406395

@@ -414,14 +403,10 @@ module Angular2 {
414403
}
415404

416405
/** Gets the value of the `name` option passed to the `@Pipe` decorator. */
417-
string getPipeName() {
418-
decorator.getOptionArgument(0, "name").mayHaveStringValue(result)
419-
}
406+
string getPipeName() { decorator.getOptionArgument(0, "name").mayHaveStringValue(result) }
420407

421408
/** Gets a reference to this pipe. */
422-
DataFlow::Node getAPipeRef() {
423-
result.asExpr().(PipeRefExpr).getName() = getPipeName()
424-
}
409+
DataFlow::Node getAPipeRef() { result.asExpr().(PipeRefExpr).getName() = getPipeName() }
425410
}
426411

427412
private class ComponentSteps extends PreCallGraphStep {
@@ -464,28 +449,25 @@ module Angular2 {
464449
* attribute. There is no AST node for the implied for-of loop.
465450
*/
466451
private class ForLoopAttribute extends HTML::Attribute {
467-
ForLoopAttribute() {
468-
getName() = "*ngFor"
469-
}
452+
ForLoopAttribute() { getName() = "*ngFor" }
470453

471454
/** Gets a data-flow node holding the value being iterated over. */
472-
DataFlow::Node getIterationDomain() {
473-
result = getAttributeValueAsNode(this)
474-
}
455+
DataFlow::Node getIterationDomain() { result = getAttributeValueAsNode(this) }
475456

476457
/** Gets the name of the variable holding the element of the current iteration. */
477-
string getIteratorName() {
478-
result = getValue().regexpCapture(" *let +(\\w+).*", 1)
479-
}
458+
string getIteratorName() { result = getValue().regexpCapture(" *let +(\\w+).*", 1) }
480459

481460
/** Gets an HTML element in which the iterator variable is in scope. */
482-
HTML::Element getAnElementInScope() {
483-
result.getParent*() = getElement()
484-
}
461+
HTML::Element getAnElementInScope() { result.getParent*() = getElement() }
485462

486463
/** Gets a reference to the iterator variable. */
487464
DataFlow::Node getAnIteratorAccess() {
488-
result = getAnElementInScope().getAnAttribute().getCodeInAttribute().(TemplateTopLevel).getAVariableUse(getIteratorName())
465+
result =
466+
getAnElementInScope()
467+
.getAnAttribute()
468+
.getCodeInAttribute()
469+
.(TemplateTopLevel)
470+
.getAVariableUse(getIteratorName())
489471
}
490472
}
491473

@@ -496,9 +478,7 @@ module Angular2 {
496478
private class ForLoopStep extends TaintTracking::AdditionalTaintStep {
497479
ForLoopAttribute attrib;
498480

499-
ForLoopStep() {
500-
this = attrib.getIterationDomain()
501-
}
481+
ForLoopStep() { this = attrib.getIterationDomain() }
502482

503483
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
504484
pred = this and
@@ -528,14 +508,17 @@ module Angular2 {
528508
private class BuiltinPipeStep extends TaintTracking::AdditionalTaintStep, DataFlow::CallNode {
529509
string name;
530510

531-
BuiltinPipeStep() {
532-
this = getAPipeCall(name)
533-
}
511+
BuiltinPipeStep() { this = getAPipeCall(name) }
534512

535513
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
536514
succ = this and
537515
exists(int i | pred = getArgument(i) |
538-
i = 0 and name = ["async", "i18nPlural", "json", "keyvalue", "lowercase", "uppercase", "titlecase", "slice"]
516+
i = 0 and
517+
name =
518+
[
519+
"async", "i18nPlural", "json", "keyvalue", "lowercase", "uppercase", "titlecase",
520+
"slice"
521+
]
539522
or
540523
i = 1 and name = "date" // date format string
541524
)
@@ -551,9 +534,7 @@ module Angular2 {
551534
* A `<mat-table>` element.
552535
*/
553536
class MatTableElement extends HTML::Element {
554-
MatTableElement() {
555-
getName() = "mat-table"
556-
}
537+
MatTableElement() { getName() = "mat-table" }
557538

558539
/** Gets the data flow node corresponding to the `[dataSource]` attribute. */
559540
DataFlow::Node getDataSourceNode() {
@@ -566,13 +547,20 @@ module Angular2 {
566547
HTML::Element getATableCell(string rowBinding) {
567548
result.getName() = "mat-cell" and
568549
result.getParent+() = this and
569-
rowBinding = result.getAttributeByName("*matCellDef").getValue().regexpCapture(" *let +(\\w+).*", 1)
550+
rowBinding =
551+
result.getAttributeByName("*matCellDef").getValue().regexpCapture(" *let +(\\w+).*", 1)
570552
}
571553

572554
/** Gets a data flow node that refers to one of the rows from the data source. */
573555
DataFlow::Node getARowRef() {
574556
exists(string rowBinding |
575-
result = getATableCell(rowBinding).getChild*().getAnAttribute().getCodeInAttribute().(TemplateTopLevel).getAVariableUse(rowBinding)
557+
result =
558+
getATableCell(rowBinding)
559+
.getChild*()
560+
.getAnAttribute()
561+
.getCodeInAttribute()
562+
.(TemplateTopLevel)
563+
.getAVariableUse(rowBinding)
576564
)
577565
}
578566
}
@@ -590,9 +578,7 @@ module Angular2 {
590578
private class MatTableTaintStep extends TaintTracking::AdditionalTaintStep {
591579
MatTableElement table;
592580

593-
MatTableTaintStep() {
594-
this = table.getDataSourceNode()
595-
}
581+
MatTableTaintStep() { this = table.getDataSourceNode() }
596582

597583
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
598584
pred = this and
@@ -614,7 +600,8 @@ module Angular2 {
614600
/** A taint step into the data array of a `MatTableDataSource` instance. */
615601
private class MatTableDataSourceStep extends TaintTracking::AdditionalTaintStep, DataFlow::NewNode {
616602
MatTableDataSourceStep() {
617-
this = DataFlow::moduleMember("@angular/material/table", "MatTableDataSource").getAnInstantiation()
603+
this =
604+
DataFlow::moduleMember("@angular/material/table", "MatTableDataSource").getAnInstantiation()
618605
}
619606

620607
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {

javascript/ql/src/semmle/javascript/frameworks/RxJS.qll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/**
22
* Provides taint steps modeling flow through `rxjs` Observable objects.
33
*/
4+
45
private import javascript
56

67
/**
78
* A step `x -> y` in `x.subscribe(y => ...)`, modeling flow out of an rxjs Observable.
89
*/
910
private class RxJsSubscribeStep extends TaintTracking::AdditionalTaintStep, DataFlow::MethodCallNode {
10-
RxJsSubscribeStep() {
11-
getMethodName() = "subscribe"
12-
}
11+
RxJsSubscribeStep() { getMethodName() = "subscribe" }
1312

1413
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
1514
pred = getReceiver() and
@@ -50,9 +49,7 @@ private predicate isIdentityPipe(DataFlow::CallNode pipe) {
5049
* A step in or out of the map callback in a call of form `x.pipe(map(y => ...))`.
5150
*/
5251
private class RxJsPipeMapStep extends TaintTracking::AdditionalTaintStep, DataFlow::MethodCallNode {
53-
RxJsPipeMapStep() {
54-
getMethodName() = "pipe"
55-
}
52+
RxJsPipeMapStep() { getMethodName() = "pipe" }
5653

5754
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
5855
pred = getReceiver() and

0 commit comments

Comments
 (0)