Skip to content

Commit 81fb126

Browse files
Merge pull request #2455 from github/robertbrignull/import-path-problem
Expand assert-pure.ql to cover common and be a path-problem query
2 parents 22172d5 + c462bc0 commit 81fb126

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
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 ImportDeclaration {
13+
VSCodeImport() { this.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+
query predicate edges(AstNode a, AstNode b) {
31+
getANonTypeOnlyImport(a) = b or
32+
a.(Import).getImportedModule() = b
33+
}
34+
1735
from Module m, VSCodeImport v
1836
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"
37+
m.getFile() instanceof PureFile and
38+
edges+(m, v)
39+
select m, m, v,
40+
"This module is not pure: it has a transitive dependency on the vscode API imported $@", v, "here"

0 commit comments

Comments
 (0)