File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments