Skip to content

Commit b8770a2

Browse files
Convert assert-pure.ql to be a path-problem query
1 parent 35a7eee commit b8770a2

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
/**
22
* @name Unwanted dependency on vscode API
3-
* @kind problem
3+
* @kind path-problem
44
* @problem.severity error
55
* @id vscode-codeql/assert-pure
66
* @description The modules stored under `pure` and tested in the `pure-tests`
77
* are intended to be "pure".
88
*/
9+
910
import javascript
1011

11-
class VSCodeImport extends ASTNode {
12-
VSCodeImport() {
13-
this.(Import).getImportedPath().getValue() = "vscode"
12+
class VSCodeImport extends AstNode {
13+
VSCodeImport() { this.(Import).getImportedPath().getValue() = "vscode" }
14+
}
15+
16+
class PureFile extends File {
17+
PureFile() {
18+
(
19+
this.getRelativePath().regexpMatch(".*/src/pure/.*") or
20+
this.getRelativePath().regexpMatch(".*/src/common/.*")
21+
) and
22+
not this.getRelativePath().regexpMatch(".*/src/common/vscode/.*")
1423
}
1524
}
1625

26+
Import getANonTypeOnlyImport(Module m) {
27+
result = m.getAnImport() and not result.(ImportDeclaration).isTypeOnly()
28+
}
29+
30+
Module getANonTypeOnlyImportedModule(Module m) {
31+
result = getANonTypeOnlyImport(m).getImportedModule()
32+
}
33+
34+
query predicate edges(AstNode a, AstNode b) {
35+
getANonTypeOnlyImport(a) = b or
36+
a.(Import).getImportedModule() = b
37+
}
38+
1739
from Module m, VSCodeImport v
1840
where
19-
m.getFile().getRelativePath().regexpMatch(".*src/pure/.*") and
20-
m.getAnImportedModule*().getAnImport() = v
21-
select m, "This module is not pure: it has a transitive dependency on the vscode API imported $@", v, "here"
41+
m.getFile() instanceof PureFile and
42+
getANonTypeOnlyImport(getANonTypeOnlyImportedModule*(m)) = v
43+
select m, m, v,
44+
"This module is not pure: it has a transitive dependency on the vscode API imported $@", v, "here"

0 commit comments

Comments
 (0)