Convert to an abstract class

This commit is contained in:
Robert
2024-03-13 16:43:42 +00:00
parent 826175ccd5
commit 280bf8b7b2
2 changed files with 34 additions and 26 deletions

32
.github/codeql/queries/ProgressBar.qll vendored Normal file
View File

@@ -0,0 +1,32 @@
import javascript
abstract class ProgressBar extends CallExpr {
ProgressBar() { any() }
abstract Function getCallback();
abstract ObjectExpr getOptions();
predicate usesToken() { this.getCallback().getNumParameter() >= 2 }
predicate isCancellable() {
this.getOptions().getPropertyByName("cancellable").getInit().(BooleanLiteral).getBoolValue() =
true
}
}
class WithProgressCall extends ProgressBar {
WithProgressCall() { this.getCalleeName() = "withProgress" }
override Function getCallback() { result = this.getArgument(0) }
override ObjectExpr getOptions() { result = this.getArgument(1) }
}
class WithInheritedProgressCall extends ProgressBar {
WithInheritedProgressCall() { this.getCalleeName() = "withInheritedProgress" }
override Function getCallback() { result = this.getArgument(1) }
override ObjectExpr getOptions() { result = this.getArgument(2) }
}

View File

@@ -10,32 +10,8 @@
*/
import javascript
import ProgressBar
class NewTokenSource extends CallExpr {
NewTokenSource() {
this.getCalleeName() = "withProgress" or this.getCalleeName() = "withInheritedProgress"
}
Function getCallback() {
this.getCalleeName() = "withProgress" and result = this.getArgument(0)
or
this.getCalleeName() = "withInheritedProgress" and result = this.getArgument(1)
}
ObjectExpr getOptions() {
this.getCalleeName() = "withProgress" and result = this.getArgument(1)
or
this.getCalleeName() = "withInheritedProgress" and result = this.getArgument(2)
}
predicate usesToken() { this.getCallback().getNumParameter() >= 2 }
predicate isCancellable() {
this.getOptions().getPropertyByName("cancellable").getInit().(BooleanLiteral).getBoolValue() =
true
}
}
from NewTokenSource t
from ProgressBar t
where t.isCancellable() and not t.usesToken()
select t, "This progress bar is cancelable but the token is not used"