Skip to content

Commit c0a65c9

Browse files
Convert to alert only first usage, instead of all other usages
1 parent ead1869 commit c0a65c9

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

.github/codeql/queries/unique-command-use.ql

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010

1111
import javascript
1212

13-
abstract class CommandUsage extends Locatable {
14-
abstract string getCommandName();
13+
class CommandName extends string {
14+
CommandName() { exists(CommandUsage e | e.getCommandName() = this) }
1515

16-
predicate isUsedFromOtherPlace() {
17-
exists(CommandUsage e | e != this and e.getCommandName() = this.getCommandName())
18-
}
16+
int getNumberOfUsages() { result = count(CommandUsage e | e.getCommandName() = this | e) }
1917

20-
predicate isFirstUsage() {
21-
forall(CommandUsage e | e.getCommandName() = this.getCommandName() |
22-
e.getLocationOrdinal() >= this.getLocationOrdinal()
18+
CommandUsage getFirstUsage() {
19+
result.getCommandName() = this and
20+
forall(CommandUsage e | e.getCommandName() = this |
21+
e.getLocationOrdinal() >= result.getLocationOrdinal()
2322
)
2423
}
24+
}
25+
26+
abstract class CommandUsage extends Locatable {
27+
abstract string getCommandName();
2528

2629
string getLocationOrdinal() {
2730
result =
@@ -81,9 +84,8 @@
8184
override string getCommandName() { result = this.getPropValue("command").getStringValue() }
8285
}
8386

84-
from CommandUsage e
85-
where
86-
e.isUsedFromOtherPlace() and
87-
not e.isFirstUsage()
88-
select e, "The " + e.getCommandName() + " command is used from another location"
87+
from CommandName c
88+
where c.getNumberOfUsages() > 1
89+
select c.getFirstUsage(),
90+
"The " + c + " command is used from " + c.getNumberOfUsages() + " locations"
8991

0 commit comments

Comments
 (0)