Skip to content

Commit 826175c

Browse files
Create token-not-used.ql
1 parent 3005dac commit 826175c

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @name Don't ignore the token for a cancelable progress bar
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id vscode-codeql/token-not-used
6+
* @description If we call `withProgress` with `cancellable: true` but then
7+
* ignore the token that is given to us, it will lead to a poor user experience
8+
* because the progress bar will appear to be canceled but it will not actually
9+
* affect the background process.
10+
*/
11+
12+
import javascript
13+
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
40+
where t.isCancellable() and not t.usesToken()
41+
select t, "This progress bar is cancelable but the token is not used"

0 commit comments

Comments
 (0)