Recursively walks the AST, checking each node against pre-filtered rules. Rules are already filtered for this file — no exclusion checks needed here.
(node: &AstNode, file_path: &str, content: &str, rules: &[&Rule], issues: &mut Vec<Issue>)
| 23 | // Recursively walks the AST, checking each node against pre-filtered rules. |
| 24 | // Rules are already filtered for this file — no exclusion checks needed here. |
| 25 | fn walk_ast(node: &AstNode, file_path: &str, content: &str, rules: &[&Rule], issues: &mut Vec<Issue>) { |
| 26 | for rule in rules.iter() { |
| 27 | if let Some(match_pattern) = &rule.ast_match { |
| 28 | if check_node_match(node, match_pattern) { |
| 29 | let line_content = content.lines().nth(node.lineno.saturating_sub(1) as usize).unwrap_or("").to_string(); |
| 30 | |
| 31 | // Respect line-level exclude_pattern on the matched line |
| 32 | if let Some(exclude) = &rule.exclude_pattern { |
| 33 | if exclude.is_match(&line_content) { |
| 34 | continue; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | issues.push(Issue::new( |
| 39 | rule.id.clone(), |
| 40 | rule.description.clone(), |
| 41 | file_path.to_string(), |
| 42 | node.lineno as usize, |
| 43 | line_content, |
| 44 | rule.severity.clone(), |
| 45 | rule.confidence.clone(), |
| 46 | rule.remediation.clone(), |
| 47 | rule.cwe.clone(), |
| 48 | )); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Recurse into children |
| 54 | for child_list in node.children.values() { |
| 55 | for child_node in child_list { |
| 56 | walk_ast(child_node, file_path, content, rules, issues); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | fn check_node_match(node: &AstNode, match_pattern: &str) -> bool { |
| 62 | let (node_type_match, props_str) = if let Some(open_paren) = match_pattern.find('(') { |
no test coverage detected