gobject-linter 0.1.2

A fast tree-sitter-based linter for GObject/C code
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
use std::collections::HashMap;

use gobject_ast::model::{
    EnumInfo, EnumValue, Expression, FileModel, ParamSpecAssignment, PropertyEnumContext,
    PropertyType, SwitchStatement, TopLevelItem, TypeInfo,
};
use heck::ToShoutySnakeCase;

use crate::{
    ast_context::AstContext,
    config::Config,
    rules::{Fix, Rule, Violation},
};

pub struct PropertyEnumConvention;

impl Rule for PropertyEnumConvention {
    fn name(&self) -> &'static str {
        "property_enum_convention"
    }

    fn description(&self) -> &'static str {
        "Enforce property enum conventions (typed or legacy style)"
    }

    fn category(&self) -> crate::rules::Category {
        crate::rules::Category::Style
    }

    fn fixable(&self) -> bool {
        true
    }

    fn config_options(&self) -> &'static [crate::rules::ConfigOption] {
        &[crate::rules::ConfigOption {
            name: "style",
            option_type: "string",
            default_value: "\"typed\"",
            example_value: "\"legacy\"",
            description: "Property enum style: \"typed\" (PROP_FOO = 1, no PROP_0/N_PROPS) or \"legacy\" (PROP_0, N_PROPS)",
        }]
    }

    fn check_all(
        &self,
        ast_context: &AstContext,
        config: &Config,
        violations: &mut Vec<Violation>,
    ) {
        // Get style configuration (default to "typed")
        let rule_config = &config.rules.property_enum_convention;
        let style = rule_config
            .options
            .get("style")
            .and_then(|v| v.as_str())
            .unwrap_or("typed");

        match style {
            "typed" => self.check_all_typed_style(ast_context, &config.style, violations),
            "legacy" => self.check_all_legacy_style(ast_context, violations),
            _ => {
                // Invalid style, default to legacy
                self.check_all_legacy_style(ast_context, violations);
            }
        }
    }
}

impl PropertyEnumConvention {
    /// Check using modern typed enum style (PROP_FOO = 1, no PROP_0/N_PROPS)
    fn check_all_typed_style(
        &self,
        ast_context: &AstContext,
        call_style: &crate::config::Style,
        violations: &mut Vec<Violation>,
    ) {
        for (path, file) in ast_context.iter_all_files() {
            // Collect N_PROPS names from enums that will be transformed
            // (skip override pattern enums and already-modern enums)
            let n_props_usage: HashMap<&str, usize> = file
                .iter_property_enums()
                .filter(|e| {
                    // Apply same checks as main loop to see if this enum will be transformed
                    let has_prop_0 = e.values.first().is_some_and(EnumValue::is_prop_0);

                    let has_n_props_at_end = e.values.last().is_some_and(EnumValue::is_prop_last);

                    let has_n_props_in_middle = e
                        .values
                        .iter()
                        .enumerate()
                        .any(|(idx, v)| idx < e.values.len() - 1 && v.is_prop_last());

                    // Only count if it will be transformed (not in-middle pattern, not already
                    // modern) Note: N_PROPS = PROP_X where PROP_X is override
                    // is still transformable
                    !has_n_props_in_middle && (has_prop_0 || has_n_props_at_end)
                })
                .filter_map(|e| {
                    e.values
                        .iter()
                        .find(|v| v.is_prop_last())
                        .map(|v| v.name.as_str())
                })
                .fold(HashMap::new(), |mut map, name| {
                    *map.entry(name).or_insert(0) += 1;
                    map
                });

            for enum_info in file.iter_property_enums() {
                // Check if this uses the old pattern: PROP_0 at start and N_PROPS at end
                let has_prop_0 = enum_info.values.first().is_some_and(EnumValue::is_prop_0);

                let has_n_props = enum_info.values.last().is_some_and(EnumValue::is_prop_last);

                // Check if N_PROPS appears in the middle (not last) - this is the override
                // properties pattern
                let has_n_props_in_middle = enum_info
                    .values
                    .iter()
                    .enumerate()
                    .any(|(idx, v)| idx < enum_info.values.len() - 1 && v.is_prop_last());

                if !has_prop_0 && !has_n_props {
                    // Already using new pattern, skip
                    continue;
                }

                // Get the names we need to work with
                let prop_0_name = enum_info.values.first().unwrap().name.as_str();
                let n_props_name = enum_info.values.last().unwrap().name.as_str();

                // Skip if this is the interface override pattern:
                // - N_PROPS in the middle
                // - N_PROPS used in switch case expressions
                if has_n_props_in_middle
                    || (has_n_props && self.n_props_used_in_switch_cases(file, n_props_name))
                {
                    // Skip: interface override pattern detected
                    continue;
                }

                let Some(ctx) = file.resolve_property_enum_context(enum_info) else {
                    continue;
                };

                let property_map = self.build_property_override_map(&ctx.gobject_type.properties);

                // Get the name of the last REAL property (the one before N_PROPS)
                // If N_PROPS = PROP_X and PROP_X is an override, find the last non-override
                // property
                let last_real_prop_name = if has_n_props && enum_info.values.len() >= 2 {
                    // Check if the value before N_PROPS is an override
                    let second_to_last = &enum_info.values[enum_info.values.len() - 2];

                    // Also check if N_PROPS = PROP_X where PROP_X is an override
                    let n_props_value = enum_info.values.last().unwrap();
                    let n_props_points_to_override = if n_props_value.value_location.is_some()
                        && n_props_value.value.is_none()
                    {
                        n_props_value
                            .value_text()
                            .and_then(|value_text| property_map.get(value_text).copied())
                            .unwrap_or(false)
                    } else {
                        false
                    };

                    if n_props_points_to_override {
                        // N_PROPS = PROP_ORIENTATION (override), so find last non-override property
                        enum_info
                            .values
                            .iter()
                            .rev()
                            .skip(1) // Skip N_PROPS
                            .find(|v| {
                                !v.is_prop_0()
                                    && !v.is_prop_last()
                                    && !property_map.get(&v.name).copied().unwrap_or(false)
                            })
                            .map_or_else(|| second_to_last.name.as_str(), |v| v.name.as_str())
                    } else {
                        second_to_last.name.as_str()
                    }
                } else {
                    enum_info.values.last().unwrap().name.as_str()
                };

                let derived_enum_name = if enum_info.name.is_none() {
                    ctx.class_type_info
                        .and_then(|ti| self.derive_enum_name_from_class_type(ti))
                } else {
                    None
                };

                let mut fixes = Vec::new();

                // Fix 0: Convert anonymous enum to typedef if needed
                if let Some(ref enum_name) = derived_enum_name {
                    fixes.extend(self.create_typedef_fixes(file, enum_info, enum_name));
                }

                // Fix 1: Remove PROP_0 line entirely (including any blank line after it)
                if has_prop_0 && enum_info.values.len() >= 2 {
                    let prop_0 = &enum_info.values[0];
                    fixes.push(Fix::delete_line_and_trailing_blank(&prop_0.location));
                }

                // Fix 2: Add " = 1" to the first real property (second value)
                if has_prop_0 && enum_info.values.len() >= 2 {
                    let first_real = &enum_info.values[1];

                    // If the property already has a value (e.g., "= 0"), remove it first
                    if first_real.value == Some(0)
                        && let Some(value_loc) = &first_real.value_location
                    {
                        // Remove existing " = 0" or "= 0" and replace with " = 1"
                        fixes.push(Fix::new(
                            first_real.name_location.end_byte,
                            value_loc.end_byte,
                            " = 1".to_string(),
                        ));
                    } else {
                        // Just insert " = 1" right after the property name
                        fixes.push(Fix::new(
                            first_real.name_location.end_byte,
                            first_real.name_location.end_byte,
                            " = 1".to_string(),
                        ));
                    }
                }

                // Fix 3: Remove N_PROPS line entirely (including any blank line before it)
                if has_n_props && enum_info.values.len() >= 2 {
                    let n_props = enum_info.values.last().unwrap();
                    fixes.push(Fix::delete_line_and_leading_blank(&n_props.location));
                }

                // Fix 4 & 5: Find GParamSpec arrays and fix both their declarations and
                // install_properties calls
                // Only fix if this N_PROPS name is unique in the file (avoid ambiguity)
                if has_n_props && n_props_usage.get(n_props_name).copied().unwrap_or(0) == 1 {
                    let array_names = self.find_and_fix_param_spec_arrays(
                        file,
                        n_props_name,
                        last_real_prop_name,
                        &mut fixes,
                    );

                    // Fix install_properties calls that use these arrays
                    for func in file.iter_class_init_functions() {
                        for call in func.find_install_properties_calls() {
                            // Second argument (index 1) should be N_PROPS
                            if let Some(arg) = call.get_arg(1)
                                && let Some(arg_str) = arg.location().as_str()
                                && arg_str == n_props_name
                            {
                                // Get the array name from third argument
                                if let Some(array_arg) = call.get_arg(2)
                                    && let Some(array_name) = array_arg.location().as_str()
                                    && array_names.contains(&array_name)
                                {
                                    let replacement =
                                        call_style.format_call("G_N_ELEMENTS", &[array_name]);
                                    fixes.push(Fix::new(
                                        arg.location().start_byte,
                                        arg.location().end_byte,
                                        replacement,
                                    ));
                                }
                            }
                        }
                    }
                }

                // Fix 6: Add enum cast to switch statements in get_property/set_property
                // This enables -Wswitch-enum to catch missing properties
                // Only apply to the specific property functions for this enum
                let enum_name = if let Some(ref name) = enum_info.name {
                    name.clone()
                } else if let Some(ref derived) = derived_enum_name {
                    derived.clone()
                } else {
                    ctx.class_type_info
                        .and_then(|ti| self.derive_enum_name_from_class_type(ti))
                        .unwrap_or_else(|| "UnknownProps".to_string())
                };

                if !enum_name.is_empty() {
                    if let Some(func_name) = ctx.get_property_func {
                        self.add_switch_cast_for_function(file, func_name, &enum_name, &mut fixes);
                    }
                    if let Some(func_name) = ctx.set_property_func {
                        self.add_switch_cast_for_function(file, func_name, &enum_name, &mut fixes);
                    }
                }

                if !fixes.is_empty() {
                    let message = if has_prop_0 && has_n_props {
                        format!(
                            "Use modern property enum pattern (remove {}, {}, start from = 1)",
                            prop_0_name, n_props_name
                        )
                    } else if has_prop_0 {
                        format!("Remove {} and start enum from = 1", prop_0_name)
                    } else {
                        format!("Remove {}", n_props_name)
                    };

                    violations.push(self.violation_with_fixes(
                        path,
                        enum_info.location.line,
                        1,
                        message,
                        fixes,
                    ));
                }
            }

            // Check modern enums (without PROP_0/N_PROPS) for outdated array sizes
            // and missing switch casts
            for enum_info in file.iter_property_enums() {
                let has_prop_0 = enum_info.values.first().is_some_and(EnumValue::is_prop_0);
                let has_n_props = enum_info.values.last().is_some_and(EnumValue::is_prop_last);

                // Skip old-style enums (already handled above)
                if has_prop_0 || has_n_props {
                    continue;
                }

                // Only check already-modern enums (ones with explicit = 1 on first value)
                let is_already_modern = enum_info
                    .values
                    .first()
                    .and_then(|v| v.value.as_ref())
                    .is_some_and(|val| *val == 1);

                if !is_already_modern {
                    continue;
                }

                let Some(ctx) = file.resolve_property_enum_context(enum_info) else {
                    continue;
                };

                let property_map = self.build_property_override_map(&ctx.gobject_type.properties);

                // Find the last real (non-override) property
                let last_real_prop = enum_info
                    .values
                    .iter()
                    .rev()
                    .find(|v| !property_map.get(&v.name).copied().unwrap_or(false));

                let Some(last_real_prop) = last_real_prop else {
                    continue;
                };

                // Check GParamSpec arrays for outdated PROP_X + 1 pattern
                self.check_outdated_array_sizes(
                    file,
                    path,
                    enum_info,
                    &last_real_prop.name,
                    violations,
                );

                self.check_modern_enum_switch_casts(file, path, enum_info, &ctx, violations);
            }
        }
    }

    /// Check using legacy enum style (PROP_0 at start, N_PROPS at end)
    fn check_all_legacy_style(&self, ast_context: &AstContext, violations: &mut Vec<Violation>) {
        // Check each file's enums
        for (path, file) in ast_context.iter_all_files() {
            // First pass: collect all existing PROP_0 variants to avoid duplicates
            let existing_prop_zeros: std::collections::HashSet<&str> = file
                .iter_property_enums()
                .flat_map(|enum_info| &enum_info.values)
                .filter_map(|val| {
                    if val.is_prop_0() {
                        Some(val.name.as_str())
                    } else {
                        None
                    }
                })
                .collect();

            let mut will_add_unprefixed_prop_zero = existing_prop_zeros.contains("PROP_0");

            // Second pass: check each enum
            for enum_info in file.iter_property_enums() {
                // Determine if we need a prefix for PROP_0
                let prefix = if will_add_unprefixed_prop_zero {
                    enum_info
                        .name
                        .as_ref()
                        .map(|name| name.to_shouty_snake_case() + "_")
                } else {
                    None
                };

                let mut fixes = Vec::new();
                let mut has_violations = false;
                let mut violation_line = enum_info.location.line;
                let mut message = String::new();

                // Check first enumerator - should be PROP_0
                if let Some(first_val) = enum_info.values.first()
                    && !first_val.is_prop_0()
                {
                    has_violations = true;
                    violation_line = enum_info.location.line;

                    // Get indentation from the source
                    let indent = first_val.location.extract_line_indentation();

                    let prop_zero_name = if let Some(ref p) = prefix {
                        format!("{}PROP_0", p)
                    } else {
                        "PROP_0".to_string()
                    };

                    // Insert PROP_0 before first property
                    let insertion = format!("{},\n{}", prop_zero_name, indent);
                    fixes.push(Fix::new(
                        first_val.location.start_byte,
                        first_val.location.start_byte,
                        insertion,
                    ));

                    // Remove " = 0" if it exists on first property
                    if first_val.value == Some(0)
                        && let Some(value_loc) = &first_val.value_location
                    {
                        fixes.push(Fix::delete(
                            first_val.name_location.end_byte,
                            value_loc.end_byte,
                        ));
                    }

                    message = format!(
                        "Property enum should start with {}, not {}",
                        prop_zero_name, first_val.name
                    );

                    // Mark that we're adding PROP_0
                    if prefix.is_none() {
                        will_add_unprefixed_prop_zero = true;
                    }
                }

                // Check last enumerator - should be N_PROPS or similar
                if let Some(last) = enum_info.values.last()
                    && !last.is_prop_last()
                {
                    has_violations = true;

                    let indent = last.location.extract_line_indentation();

                    let n_props_name = if let Some(ref p) = prefix {
                        format!("{}N_PROPS", p)
                    } else {
                        "N_PROPS".to_string()
                    };

                    // Insert N_PROPS after last enumerator
                    let insertion = format!(",\n{}{}", indent, n_props_name);
                    fixes.push(Fix::new(
                        last.location.end_byte,
                        last.location.end_byte,
                        insertion,
                    ));

                    if !message.is_empty() {
                        message.push_str(&format!(", and should end with {}", n_props_name));
                    } else {
                        message = format!("Property enum should end with {}", n_props_name);
                    }
                }

                if has_violations {
                    violations.push(self.violation_with_fixes(
                        path,
                        violation_line,
                        1,
                        message,
                        fixes,
                    ));
                }
            }
        }
    }

    /// Find GParamSpec arrays that use N_PROPS, fix their declarations, and
    /// return their names e.g., static GParamSpec *props[N_PROPS] -> static
    /// GParamSpec *props[LAST_PROP + 1]
    fn find_and_fix_param_spec_arrays<'a>(
        &self,
        file: &'a FileModel,
        n_props_name: &str,
        last_prop_name: &str,
        fixes: &mut Vec<Fix>,
    ) -> Vec<&'a str> {
        let mut array_names = Vec::new();

        for item in file.iter_all_items() {
            let TopLevelItem::Declaration(decl) = item else {
                continue;
            };
            if !decl.type_info.is_base_type("GParamSpec") || !decl.type_info.is_pointer() {
                continue;
            }
            let Some(Expression::Identifier(size_id)) = &decl.array_size else {
                continue;
            };
            if size_id.name != n_props_name {
                continue;
            }
            fixes.push(Fix::new(
                size_id.location.start_byte,
                size_id.location.end_byte,
                format!("{} + 1", last_prop_name),
            ));
            array_names.push(decl.name.as_str());
        }

        array_names
    }

    /// Add switch cast fix for a specific function
    fn add_switch_cast_for_function(
        &self,
        file: &FileModel,
        func_name: &str,
        enum_name: &str,
        fixes: &mut Vec<Fix>,
    ) {
        // Find the function definition
        for func in file.iter_function_definitions() {
            if func.name != func_name {
                continue;
            }

            // Find switch statements using iterator to handle nested cases
            for stmt in &func.body_statements {
                for switch_stmt in stmt.iter_switches() {
                    self.add_switch_cast_if_needed(switch_stmt, enum_name, fixes);
                }
            }
        }
    }

    /// Helper to add switch cast if not already present
    fn add_switch_cast_if_needed(
        &self,
        switch_stmt: &SwitchStatement,
        enum_name: &str,
        fixes: &mut Vec<Fix>,
    ) {
        // Check if the condition is already a cast to this enum type
        let already_cast = match &switch_stmt.condition {
            Expression::Cast(cast) => {
                // Check if cast type contains the enum name
                cast.type_info.base_type.contains(enum_name)
            }
            _ => false,
        };

        if !already_cast {
            // Add fix to wrap the condition in a cast
            let cast_expr = format!("({}) ", enum_name);
            fixes.push(Fix::new(
                switch_stmt.condition_location.start_byte,
                switch_stmt.condition_location.start_byte,
                cast_expr,
            ));
        }
    }

    /// Derive enum name from class type base
    /// e.g., "ClutterActorClass" -> Some("ClutterActorProps")
    /// e.g., "MyObjectClass" -> Some("MyObjectProps")
    fn derive_enum_name_from_class_type(&self, type_info: &TypeInfo) -> Option<String> {
        type_info
            .base_type
            .strip_suffix("Class")
            .map(|base_name| format!("{}Props", base_name))
    }

    /// Check if N_PROPS is used in switch case expressions in
    /// get_property/set_property e.g., case N_PROPS +
    /// META_DBUS_SESSION_PROP_FOO:
    fn n_props_used_in_switch_cases(&self, file: &FileModel, n_props_name: &str) -> bool {
        for func in file.iter_function_definitions() {
            if !func.name.ends_with("_get_property") && !func.name.ends_with("_set_property") {
                continue;
            }

            // Check all switch statements in the function
            for stmt in &func.body_statements {
                for switch_stmt in stmt.iter_switches() {
                    // Check if any case label uses n_props_name
                    for case in &switch_stmt.cases {
                        if let Some(value_expr) = &case.label.value
                            && value_expr.contains_identifier(n_props_name)
                        {
                            return true;
                        }
                    }
                }
            }
        }
        false
    }

    /// Build a map of enum value name -> whether it's an override property
    /// from the given param_spec assignments
    fn build_property_override_map(
        &self,
        assignments: &[ParamSpecAssignment],
    ) -> HashMap<String, bool> {
        let mut property_map = HashMap::new();

        for assignment in assignments {
            // Only track assignments that have an enum_value (ArraySubscript and
            // OverrideProperty)
            if let Some(enum_value) = assignment.enum_value() {
                let is_override =
                    matches!(assignment.property().property_type, PropertyType::Override);
                property_map.insert(enum_value.to_string(), is_override);
            }
        }

        property_map
    }

    /// Check if modern enum needs switch casts in getter/setter (and typedef if
    /// anonymous)
    fn check_modern_enum_switch_casts(
        &self,
        file: &FileModel,
        path: &std::path::Path,
        enum_info: &EnumInfo,
        ctx: &PropertyEnumContext<'_>,
        violations: &mut Vec<Violation>,
    ) {
        let enum_name = if let Some(ref name) = enum_info.name {
            name.clone()
        } else {
            match ctx
                .class_type_info
                .and_then(|ti| self.derive_enum_name_from_class_type(ti))
            {
                Some(name) => name,
                None => return,
            }
        };

        let mut fixes = Vec::new();

        // If anonymous enum, add typedef
        if enum_info.name.is_none() {
            fixes.extend(self.create_typedef_fixes(file, enum_info, &enum_name));
        }

        // Add switch casts for getter/setter functions
        if let Some(func_name) = ctx.get_property_func {
            self.add_switch_cast_for_function(file, func_name, &enum_name, &mut fixes);
        }
        if let Some(func_name) = ctx.set_property_func {
            self.add_switch_cast_for_function(file, func_name, &enum_name, &mut fixes);
        }

        // Only create a violation if we actually need to add fixes
        if !fixes.is_empty() {
            let message = if enum_info.name.is_none() {
                format!(
                    "Add typedef {} and use cast in switch statements for type safety",
                    enum_name
                )
            } else {
                format!(
                    "Add ({}) cast to switch statements for type safety",
                    enum_name
                )
            };

            violations.push(self.violation_with_fixes(
                path,
                enum_info.location.line,
                1,
                message,
                fixes,
            ));
        }
    }

    /// Create fixes to convert an anonymous enum to a typedef enum
    fn create_typedef_fixes(
        &self,
        _file: &FileModel,
        enum_info: &EnumInfo,
        enum_name: &str,
    ) -> Vec<Fix> {
        let mut fixes = Vec::new();

        // Add "typedef " before "enum"
        fixes.push(Fix::new(
            enum_info.location.start_byte,
            enum_info.location.start_byte,
            "typedef ".to_string(),
        ));

        // Add enum name and semicolon after the closing brace
        let semicolon_end = enum_info.body_location.find_after(b';');
        if semicolon_end > enum_info.body_location.end_byte {
            // Replace the semicolon with " EnumName;"
            fixes.push(Fix::new(
                semicolon_end - 1,
                semicolon_end,
                format!(" {};", enum_name),
            ));
        }

        fixes
    }

    /// Check for GParamSpec arrays with outdated PROP_X + 1 sizes
    fn check_outdated_array_sizes(
        &self,
        file: &FileModel,
        path: &std::path::Path,
        enum_info: &EnumInfo,
        expected_last_prop: &str,
        violations: &mut Vec<Violation>,
    ) {
        // Build set of property names from this enum
        let property_names: std::collections::HashSet<&str> =
            enum_info.values.iter().map(|v| v.name.as_str()).collect();

        // Find all GParamSpec pointer arrays
        let arrays = file.find_typed_arrays("GParamSpec", true, None);

        for decl in arrays {
            // Check for PROP_X + 1 pattern
            if let Some(Expression::Binary(binary)) = &decl.array_size
                && let Expression::Identifier(prop_id) = &*binary.left
                && property_names.contains(prop_id.name.as_str())
            {
                // This array uses a property from our enum
                // Check if this property is outdated (not the expected last property)
                if prop_id.name != expected_last_prop {
                    let replacement = format!("{} + 1", expected_last_prop);
                    let fix = Fix::new(
                        binary.location.start_byte,
                        binary.location.end_byte,
                        replacement,
                    );

                    violations.push(self.violation_with_fixes_at(
                        path,
                        &binary.location,
                        format!(
                            "GParamSpec array size uses outdated property (should be {} + 1)",
                            expected_last_prop
                        ),
                        vec![fix],
                    ));
                }
            }
        }
    }
}