mirror of
https://github.com/github/codeql.git
synced 2025-12-28 06:36:33 +01:00
31 lines
675 B
Plaintext
31 lines
675 B
Plaintext
/**
|
|
* @name Futile conditional
|
|
* @description If-statement with an empty then-branch and no else-branch.
|
|
* @kind problem
|
|
* @problem.severity warning
|
|
* @precision very-high
|
|
* @id cs/useless-if-statement
|
|
* @tags reliability
|
|
* readability
|
|
*/
|
|
|
|
import csharp
|
|
|
|
predicate emptyStmt(Stmt s) {
|
|
s instanceof EmptyStmt
|
|
or
|
|
s =
|
|
any(BlockStmt bs |
|
|
bs.getNumberOfStmts() = 0
|
|
or
|
|
bs.getNumberOfStmts() = 1 and
|
|
emptyStmt(bs.getStmt(0))
|
|
)
|
|
}
|
|
|
|
from IfStmt ifstmt
|
|
where
|
|
emptyStmt(ifstmt.getThen()) and
|
|
(not exists(ifstmt.getElse()) or emptyStmt(ifstmt.getElse()))
|
|
select ifstmt, "If-statement with an empty then-branch and no else-branch."
|