mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: Add example from the basic-query-for-rust-code.rst.
This commit is contained in:
15
rust/ql/examples/snippets/empty_if.ql
Normal file
15
rust/ql/examples/snippets/empty_if.ql
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name Empty 'if' statement
|
||||
* @description Finds 'if' statements where the "then" branch is empty and no
|
||||
* "else" branch exists.
|
||||
* @id rust/examples/empty-if
|
||||
* @tags example
|
||||
*/
|
||||
|
||||
import rust
|
||||
|
||||
from IfExpr ifExpr
|
||||
where
|
||||
ifExpr.getThen().(BlockExpr).getStmtList().getNumberOfStmtOrExpr() = 0 and
|
||||
not exists(ifExpr.getElse())
|
||||
select ifExpr, "This 'if' expression is redundant."
|
||||
Reference in New Issue
Block a user