Skip to main content

gobject_linter/rules/
use_g_strcmp0.rs

1use gobject_ast::model::{FileModel, FunctionDefItem};
2
3use crate::{
4    ast_context::AstContext,
5    config::Config,
6    rules::{FunctionRename, Rule, Violation},
7};
8
9const RENAMES: &[FunctionRename] = &[FunctionRename {
10    from: "strcmp",
11    to: Some("g_strcmp0"),
12    message: "Use g_strcmp0() instead of strcmp() — g_strcmp0 is NULL-safe",
13}];
14
15pub struct UseGStrcmp0;
16
17impl Rule for UseGStrcmp0 {
18    fn name(&self) -> &'static str {
19        "use_g_strcmp0"
20    }
21
22    fn description(&self) -> &'static str {
23        "Suggest g_strcmp0 instead of strcmp if arguments can be NULL (NULL-safe)"
24    }
25
26    fn category(&self) -> crate::rules::Category {
27        crate::rules::Category::Style
28    }
29
30    fn fixable(&self) -> bool {
31        true
32    }
33
34    fn min_glib_version(&self) -> Option<(u32, u32)> {
35        Some((2, 16))
36    }
37
38    fn check_func_impl(
39        &self,
40        _ast_context: &AstContext,
41        _config: &Config,
42        func: &FunctionDefItem,
43        file: &FileModel,
44        violations: &mut Vec<Violation>,
45    ) {
46        self.check_function_renames(func, file, _config, violations, RENAMES);
47    }
48}