Skip to content

Commit 8480ae1

Browse files
committed
nits
1 parent 7cea74a commit 8480ae1

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

crates/lint/src/sol/gas/unwrapped_modifier_logic.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ impl<'ast> EarlyLintPass<'ast> for UnwrappedModifierLogic {
2020
}
2121

2222
// If modifier has no contents, skip.
23-
let body = match &func.body {
24-
Some(body) => body,
25-
_ => return,
26-
};
23+
let Some(body) = &func.body else { return };
2724

2825
// If body contains unwrapped logic, emit.
2926
if body.iter().any(|stmt| !is_valid_stmt(stmt))
@@ -47,21 +44,16 @@ fn is_valid_stmt(stmt: &Stmt<'_>) -> bool {
4744
}
4845
}
4946

47+
// TODO: Support library member calls like `Lib.foo` (throws false positives).
5048
fn is_valid_expr(expr: &solar_ast::Expr<'_>) -> bool {
51-
match &expr.kind {
52-
// If the expression is a function call...
53-
ExprKind::Call(func_expr, _) => match &func_expr.kind {
54-
// If the expression is a built-in control flow function, emit.
55-
ExprKind::Ident(ident) => !matches!(ident.name.as_str(), "require" | "assert"),
56-
57-
// If the expression is a member call, emit.
58-
ExprKind::Member(_, _) => false, // TODO: enable library calls
59-
60-
// Disallow all other expressions.
61-
_ => false,
62-
},
63-
64-
// Disallow all other expressions.
65-
_ => false,
49+
// If the expression is a call, continue.
50+
if let ExprKind::Call(func_expr, _) = &expr.kind
51+
&& let ExprKind::Ident(ident) = &func_expr.kind
52+
{
53+
// If the call is a built-in control flow function, emit.
54+
return !matches!(ident.name.as_str(), "require" | "assert");
6655
}
56+
57+
// Disallow all other expressions.
58+
false
6759
}

0 commit comments

Comments
 (0)