diff --git a/ql/consistency-queries/AstConsistency.ql b/ql/consistency-queries/AstConsistency.ql index 773b6c8b898..378c9554f66 100644 --- a/ql/consistency-queries/AstConsistency.ql +++ b/ql/consistency-queries/AstConsistency.ql @@ -1,10 +1 @@ -import ql -private import codeql_ql.ast.internal.AstNodes as AstNodes - -query AstNode nonTotalGetParent() { - exists(AstNodes::toQL(result).getParent()) and - not exists(result.getParent()) and - not result.getLocation().getStartColumn() = 1 and // startcolumn = 1 <=> top level in file <=> fine to have no parent - not result instanceof YAML::YAMLNode and // parents for YAML doens't work - not (result instanceof QLDoc and result.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up -} +private import codeql_ql.ast.internal.AstNodes::AstConsistency diff --git a/ql/src/codeql_ql/ast/internal/AstNodes.qll b/ql/src/codeql_ql/ast/internal/AstNodes.qll index 9e5b8cb99ab..d6f1a97bb26 100644 --- a/ql/src/codeql_ql/ast/internal/AstNodes.qll +++ b/ql/src/codeql_ql/ast/internal/AstNodes.qll @@ -209,3 +209,16 @@ class TTypeDeclaration = TClass or TNewType or TNewTypeBranch; class TModuleDeclaration = TClasslessPredicate or TModule or TClass or TNewType; class TVarDef = TVarDecl or TAsExpr; + +module AstConsistency { + import ql + + query predicate nonTotalGetParent(AstNode node) { + exists(toQL(node).getParent()) and + not exists(node.getParent()) and + not node.getLocation().getStartColumn() = 1 and // startcolumn = 1 <=> top level in file <=> fine to have no parent + exists(node.toString()) and // <- there are a few parse errors in "global-data-flow-java-1.ql", this way we filter them out. + not node instanceof YAML::YAMLNode and // parents for YAML doens't work + not (node instanceof QLDoc and node.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up + } +} diff --git a/ql/src/queries/diagnostics/EmptyConsistencies.ql b/ql/src/queries/diagnostics/EmptyConsistencies.ql index 884ae0e60a0..11ee9ccb4f8 100644 --- a/ql/src/queries/diagnostics/EmptyConsistencies.ql +++ b/ql/src/queries/diagnostics/EmptyConsistencies.ql @@ -14,6 +14,7 @@ import codeql_ql.ast.internal.Type::TyConsistency as TypeConsistency import codeql_ql.ast.internal.Builtins::BuildinsConsistency as BuildinsConsistency import codeql_ql.ast.internal.Module::ModConsistency as ModConsistency import codeql_ql.ast.internal.Variable::VarConsistency as VarConsistency +import codeql_ql.ast.internal.AstNodes::AstConsistency as AstConsistency from AstNode node, string msg where @@ -30,6 +31,8 @@ where TypeConsistency::multiplePrimitivesExpr(node, _, _) and msg = "TypeConsistency::multiplePrimitivesExpr" or + AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent" + or //or // has 1 result, but the CodeQL compiler also can't figure out that one. I suppoed the file is never imported. //TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve" //or // has 1 result, but the CodeQL compiler also can't figure out that one. Same file as above.