Files
codeql/python/ql/src/Statements/UnnecessaryPass.ql
2025-06-19 14:07:42 +01:00

34 lines
728 B
Plaintext

/**
* @name Unnecessary pass
* @description Unnecessary 'pass' statement
* @kind problem
* @tags quality
* 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."