Skip to main content

luaur_analysis/methods/
lint_unused_function_visit_linter.rs

1use crate::records::lint_unused_function::LintUnusedFunction;
2use luaur_ast::records::ast_expr::AstExpr;
3use luaur_ast::records::ast_expr_global::AstExprGlobal;
4use luaur_ast::records::ast_node::AstNode;
5use luaur_ast::records::ast_stat_function::AstStatFunction;
6
7impl LintUnusedFunction {
8    pub fn visit_ast_stat_function(&mut self, node: *mut AstStatFunction) -> bool {
9        unsafe {
10            let name = (*node).name;
11            let expr = luaur_ast::rtti::ast_node_as::<AstExprGlobal>(name as *mut AstNode);
12            if !expr.is_null() {
13                let g = self.globals.get_or_insert((*expr).name);
14                g.function = true;
15                g.location = (*expr).base.base.location;
16
17                luaur_ast::visit::ast_expr_visit((*node).func as *mut AstExpr, self);
18
19                return false;
20            }
21        }
22
23        true
24    }
25}