Skip to content

Commit 280bf8b

Browse files
Convert to an abstract class
1 parent 826175c commit 280bf8b

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import javascript
2+
3+
abstract class ProgressBar extends CallExpr {
4+
ProgressBar() { any() }
5+
6+
abstract Function getCallback();
7+
8+
abstract ObjectExpr getOptions();
9+
10+
predicate usesToken() { this.getCallback().getNumParameter() >= 2 }
11+
12+
predicate isCancellable() {
13+
this.getOptions().getPropertyByName("cancellable").getInit().(BooleanLiteral).getBoolValue() =
14+
true
15+
}
16+
}
17+
18+
class WithProgressCall extends ProgressBar {
19+
WithProgressCall() { this.getCalleeName() = "withProgress" }
20+
21+
override Function getCallback() { result = this.getArgument(0) }
22+
23+
override ObjectExpr getOptions() { result = this.getArgument(1) }
24+
}
25+
26+
class WithInheritedProgressCall extends ProgressBar {
27+
WithInheritedProgressCall() { this.getCalleeName() = "withInheritedProgress" }
28+
29+
override Function getCallback() { result = this.getArgument(1) }
30+
31+
override ObjectExpr getOptions() { result = this.getArgument(2) }
32+
}

.github/codeql/queries/token-not-used.ql

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,8 @@
1010
*/
1111

1212
import javascript
13+
import ProgressBar
1314

14-
class NewTokenSource extends CallExpr {
15-
NewTokenSource() {
16-
this.getCalleeName() = "withProgress" or this.getCalleeName() = "withInheritedProgress"
17-
}
18-
19-
Function getCallback() {
20-
this.getCalleeName() = "withProgress" and result = this.getArgument(0)
21-
or
22-
this.getCalleeName() = "withInheritedProgress" and result = this.getArgument(1)
23-
}
24-
25-
ObjectExpr getOptions() {
26-
this.getCalleeName() = "withProgress" and result = this.getArgument(1)
27-
or
28-
this.getCalleeName() = "withInheritedProgress" and result = this.getArgument(2)
29-
}
30-
31-
predicate usesToken() { this.getCallback().getNumParameter() >= 2 }
32-
33-
predicate isCancellable() {
34-
this.getOptions().getPropertyByName("cancellable").getInit().(BooleanLiteral).getBoolValue() =
35-
true
36-
}
37-
}
38-
39-
from NewTokenSource t
15+
from ProgressBar t
4016
where t.isCancellable() and not t.usesToken()
4117
select t, "This progress bar is cancelable but the token is not used"

0 commit comments

Comments
 (0)