Merge pull request #2455 from github/robertbrignull/import-path-problem

Expand assert-pure.ql to cover common and be a path-problem query
This commit is contained in:
Robert
2023-05-31 09:15:54 +01:00
committed by GitHub

View File

@@ -1,21 +1,40 @@
/**
* @name Unwanted dependency on vscode API
* @kind problem
* @kind path-problem
* @problem.severity error
* @id vscode-codeql/assert-pure
* @description The modules stored under `pure` and tested in the `pure-tests`
* are intended to be "pure".
*/
import javascript
class VSCodeImport extends ASTNode {
VSCodeImport() {
this.(Import).getImportedPath().getValue() = "vscode"
class VSCodeImport extends ImportDeclaration {
VSCodeImport() { this.getImportedPath().getValue() = "vscode" }
}
class PureFile extends File {
PureFile() {
(
this.getRelativePath().regexpMatch(".*/src/pure/.*") or
this.getRelativePath().regexpMatch(".*/src/common/.*")
) and
not this.getRelativePath().regexpMatch(".*/src/common/vscode/.*")
}
}
Import getANonTypeOnlyImport(Module m) {
result = m.getAnImport() and not result.(ImportDeclaration).isTypeOnly()
}
query predicate edges(AstNode a, AstNode b) {
getANonTypeOnlyImport(a) = b or
a.(Import).getImportedModule() = b
}
from Module m, VSCodeImport v
where
m.getFile().getRelativePath().regexpMatch(".*src/pure/.*") and
m.getAnImportedModule*().getAnImport() = v
select m, "This module is not pure: it has a transitive dependency on the vscode API imported $@", v, "here"
m.getFile() instanceof PureFile and
edges+(m, v)
select m, m, v,
"This module is not pure: it has a transitive dependency on the vscode API imported $@", v, "here"