Skip to content

Commit 509e77b

Browse files
committed
add nonTotalGetParent to the list of empty consistency queries
1 parent 9a73c36 commit 509e77b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
import ql
2-
private import codeql_ql.ast.internal.AstNodes as AstNodes
3-
4-
query AstNode nonTotalGetParent() {
5-
exists(AstNodes::toQL(result).getParent()) and
6-
not exists(result.getParent()) and
7-
not result.getLocation().getStartColumn() = 1 and // startcolumn = 1 <=> top level in file <=> fine to have no parent
8-
not result instanceof YAML::YAMLNode and // parents for YAML doens't work
9-
not (result instanceof QLDoc and result.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up
10-
}
1+
private import codeql_ql.ast.internal.AstNodes::AstConsistency

ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,16 @@ class TTypeDeclaration = TClass or TNewType or TNewTypeBranch;
209209
class TModuleDeclaration = TClasslessPredicate or TModule or TClass or TNewType;
210210

211211
class TVarDef = TVarDecl or TAsExpr;
212+
213+
module AstConsistency {
214+
import ql
215+
216+
query predicate nonTotalGetParent(AstNode node) {
217+
exists(toQL(node).getParent()) and
218+
not exists(node.getParent()) and
219+
not node.getLocation().getStartColumn() = 1 and // startcolumn = 1 <=> top level in file <=> fine to have no parent
220+
exists(node.toString()) and // <- there are a few parse errors in "global-data-flow-java-1.ql", this way we filter them out.
221+
not node instanceof YAML::YAMLNode and // parents for YAML doens't work
222+
not (node instanceof QLDoc and node.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up
223+
}
224+
}

ql/src/queries/diagnostics/EmptyConsistencies.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import codeql_ql.ast.internal.Type::TyConsistency as TypeConsistency
1414
import codeql_ql.ast.internal.Builtins::BuildinsConsistency as BuildinsConsistency
1515
import codeql_ql.ast.internal.Module::ModConsistency as ModConsistency
1616
import codeql_ql.ast.internal.Variable::VarConsistency as VarConsistency
17+
import codeql_ql.ast.internal.AstNodes::AstConsistency as AstConsistency
1718

1819
from AstNode node, string msg
1920
where
@@ -30,6 +31,8 @@ where
3031
TypeConsistency::multiplePrimitivesExpr(node, _, _) and
3132
msg = "TypeConsistency::multiplePrimitivesExpr"
3233
or
34+
AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent"
35+
or
3336
//or // has 1 result, but the CodeQL compiler also can't figure out that one. I suppoed the file is never imported.
3437
//TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
3538
//or // has 1 result, but the CodeQL compiler also can't figure out that one. Same file as above.

0 commit comments

Comments
 (0)