Files
codeql/rust/ql/examples/snippets/empty_if.ql
Geoffrey White 109abddc36 Apply suggestions from code review
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
2025-11-11 09:32:14 +00:00

19 lines
481 B
Plaintext

/**
* @name Empty 'if' expression
* @description Finds 'if' expressions where the "then" branch is empty and no
* "else" branch exists.
* @id rust/examples/empty-if
* @tags example
*/
import rust
// find 'if' expressions...
from IfExpr ifExpr
where
// where the 'then' branch is empty
ifExpr.getThen().getStmtList().getNumberOfStmtOrExpr() = 0 and
// and no 'else' branch exists
not ifExpr.hasElse()
select ifExpr, "This 'if' expression is redundant."