Simplify now we've deleted withInheritedProgress

This commit is contained in:
Robert
2024-03-14 16:02:37 +00:00
parent 115ff838c5
commit d65e6bea53
3 changed files with 6 additions and 26 deletions

View File

@@ -1,36 +1,16 @@
import javascript import javascript
abstract class ProgressBar extends CallExpr { class WithProgressCall extends CallExpr {
ProgressBar() { any() } WithProgressCall() { this.getCalleeName() = "withProgress" }
abstract Function getCallback();
abstract ObjectExpr getOptions();
predicate usesToken() { exists(this.getTokenParameter()) } predicate usesToken() { exists(this.getTokenParameter()) }
Parameter getTokenParameter() { result = this.getCallback().getParameter(1) } Parameter getTokenParameter() { result = this.getArgument(0).(Function).getParameter(1) }
Property getCancellableProperty() { result = this.getOptions().getPropertyByName("cancellable") } Property getCancellableProperty() { result = this.getArgument(1).(ObjectExpr).getPropertyByName("cancellable") }
predicate isCancellable() { predicate isCancellable() {
this.getCancellableProperty().getInit().(BooleanLiteral).getBoolValue() = this.getCancellableProperty().getInit().(BooleanLiteral).getBoolValue() =
true 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

@@ -12,7 +12,7 @@
import javascript import javascript
import ProgressBar import ProgressBar
from ProgressBar t from WithProgressCall t
where not t.isCancellable() and t.usesToken() where not t.isCancellable() and t.usesToken()
select t, select t,
"The $@ should not be used when the progress bar is not cancellable. Either stop using the $@ or mark the progress bar as cancellable.", "The $@ should not be used when the progress bar is not cancellable. Either stop using the $@ or mark the progress bar as cancellable.",

View File

@@ -13,6 +13,6 @@
import javascript import javascript
import ProgressBar import ProgressBar
from ProgressBar t from WithProgressCall t
where t.isCancellable() and not t.usesToken() where t.isCancellable() and not t.usesToken()
select t, "This progress bar is $@ but the token is not used. Either use the token or mark the progress bar as not cancellable.", t.getCancellableProperty(), "cancellable" select t, "This progress bar is $@ but the token is not used. Either use the token or mark the progress bar as not cancellable.", t.getCancellableProperty(), "cancellable"