still flag single-expression files that contain a function

This commit is contained in:
Erik Krogh Kristensen
2020-05-04 18:28:06 +02:00
parent ffdbe31a30
commit eb7e0d6a62
2 changed files with 7 additions and 2 deletions

View File

@@ -159,6 +159,10 @@ predicate hasNoEffect(Expr e) {
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":" and
// exclude the first statement of a try block
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr() and
// exclude expressions that are alone in a file
not e.getParent().(ExprStmt).getParent().(TopLevel).getNumChild() = 1
// exclude expressions that are alone in a file, and file doesn't contain a function.
not exists(TopLevel top |
top = e.getParent().(ExprStmt).getParent() and
top.getNumChild() = 1 and
not exists(Function fun | fun.getEnclosingContainer() = top)
)
}

View File

@@ -0,0 +1 @@
["foo", "bar", 123]