|
1 | 1 | /** |
2 | 2 | * @name Unwanted dependency on vscode API |
3 | | - * @kind problem |
| 3 | + * @kind path-problem |
4 | 4 | * @problem.severity error |
5 | 5 | * @id vscode-codeql/assert-pure |
6 | 6 | * @description The modules stored under `pure` and tested in the `pure-tests` |
7 | 7 | * are intended to be "pure". |
8 | 8 | */ |
| 9 | + |
9 | 10 | import javascript |
10 | 11 |
|
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/.*") |
14 | 23 | } |
15 | 24 | } |
16 | 25 |
|
| 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 | + |
17 | 35 | from Module m, VSCodeImport v |
18 | 36 | 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