Skip to main content

gobject_linter/rules/
no_g_auto_macros.rs

1use gobject_ast::model::{FileModel, FunctionDefItem};
2
3use crate::{
4    ast_context::AstContext,
5    config::Config,
6    rules::{Rule, Violation},
7};
8
9pub struct NoGAutoMacros;
10
11impl Rule for NoGAutoMacros {
12    fn name(&self) -> &'static str {
13        "no_g_auto_macros"
14    }
15
16    fn description(&self) -> &'static str {
17        "Forbid g_auto* macros (g_autoptr, g_autofree, etc.) for MSVC compatibility"
18    }
19
20    fn category(&self) -> crate::rules::Category {
21        crate::rules::Category::Portability
22    }
23
24    fn check_func_impl(
25        &self,
26        _ast_context: &AstContext,
27        _config: &Config,
28        func: &FunctionDefItem,
29        file: &FileModel,
30        violations: &mut Vec<Violation>,
31    ) {
32        // Check all variable declarations in the function
33        for stmt in &func.body_statements {
34            for decl in stmt.iter_declarations() {
35                if let Some(auto_macro) = &decl.type_info.auto_cleanup {
36                    violations.push(self.violation_at(
37                        &file.path,
38                        &decl.location,
39                        format!("{auto_macro} requires compiler cleanup attribute support",),
40                    ));
41                }
42            }
43        }
44    }
45}