Skip to content

Commit 3a9da12

Browse files
committed
simplify claude's shit lol
1 parent c604abc commit 3a9da12

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

crates/lint/src/sol/info/unsafe_cheatcodes.rs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use crate::{
33
linter::{EarlyLintPass, LintContext},
44
sol::{Severity, SolLint},
55
};
6-
use solar_ast::{Expr, ExprKind, ItemFunction, visit::Visit};
7-
use std::ops::ControlFlow;
6+
use solar_ast::{Expr, ExprKind};
87

98
declare_forge_lint!(
109
UNSAFE_CHEATCODE_USAGE,
@@ -13,43 +12,25 @@ declare_forge_lint!(
1312
"usage of unsafe cheatcodes that can perform dangerous operations"
1413
);
1514

16-
impl<'ast> EarlyLintPass<'ast> for UnsafeCheatcodes {
17-
fn check_item_function(&mut self, ctx: &LintContext<'_>, func: &'ast ItemFunction<'ast>) {
18-
if let Some(body) = &func.body {
19-
let mut checker = UnsafeCheatcodeChecker {
20-
ctx,
21-
unsafe_cheatcodes: &[
22-
"ffi",
23-
"readFile",
24-
"readLine",
25-
"writeFile",
26-
"writeLine",
27-
"removeFile",
28-
"closeFile",
29-
"setEnv",
30-
"deriveKey",
31-
],
32-
};
33-
let _ = checker.visit_block(body);
34-
}
35-
}
36-
}
15+
const UNSAFE_CHEATCODES: [&'static str; 9] = [
16+
"ffi",
17+
"readFile",
18+
"readLine",
19+
"writeFile",
20+
"writeLine",
21+
"removeFile",
22+
"closeFile",
23+
"setEnv",
24+
"deriveKey",
25+
];
3726

38-
struct UnsafeCheatcodeChecker<'a, 's> {
39-
ctx: &'a LintContext<'s>,
40-
unsafe_cheatcodes: &'a [&'a str],
41-
}
42-
43-
impl<'ast> Visit<'ast> for UnsafeCheatcodeChecker<'_, '_> {
44-
type BreakValue = ();
45-
46-
fn visit_expr(&mut self, expr: &'ast Expr<'ast>) -> ControlFlow<Self::BreakValue> {
27+
impl<'ast> EarlyLintPass<'ast> for UnsafeCheatcodes {
28+
fn check_expr(&mut self, ctx: &LintContext<'_>, expr: &'ast Expr<'ast>) {
4729
if let ExprKind::Call(lhs, _args) = &expr.kind
4830
&& let ExprKind::Member(_lhs, member) = &lhs.kind
49-
&& self.unsafe_cheatcodes.iter().any(|&c| c == member.as_str())
31+
&& UNSAFE_CHEATCODES.iter().any(|&c| c == member.as_str())
5032
{
51-
self.ctx.emit(&UNSAFE_CHEATCODE_USAGE, member.span);
33+
ctx.emit(&UNSAFE_CHEATCODE_USAGE, member.span);
5234
}
53-
self.walk_expr(expr)
5435
}
5536
}

0 commit comments

Comments
 (0)