Files
codeql/python/ql/src/Statements/UnnecessaryPass.ql
Taus Brock-Nannestad f07a7bf8cf Python: Autoformat everything using qlformat.
Will need subsequent PRs fixing up test failures (due to deprecated
methods moving around), but other than that everything should be
straight-forward.
2020-07-07 15:43:52 +02:00

33 lines
711 B
Plaintext

/**
* @name Unnecessary pass
* @description Unnecessary 'pass' statement
* @kind problem
* @tags maintainability
* useless-code
* @problem.severity warning
* @sub-severity low
* @precision very-high
* @id py/unnecessary-pass
*/
import python
predicate is_doc_string(ExprStmt s) {
s.getValue() instanceof Unicode or s.getValue() instanceof Bytes
}
predicate has_doc_string(StmtList stmts) {
stmts.getParent() instanceof Scope and
is_doc_string(stmts.getItem(0))
}
from Pass p, StmtList list
where
list.getAnItem() = p and
(
strictcount(list.getAnItem()) = 2 and not has_doc_string(list)
or
strictcount(list.getAnItem()) > 2
)
select p, "Unnecessary 'pass' statement."