oxicop 0.2.0

A blazing-fast Ruby linter and formatter, reimplemented in Rust
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//! Naming convention cops for Ruby code.
//!
//! These cops enforce Ruby naming conventions:
//! - Methods: snake_case
//! - Variables: snake_case
//! - Constants: SCREAMING_SNAKE_CASE
//! - Classes/Modules: PascalCase

use once_cell::sync::Lazy;
use regex::Regex;

use crate::cop::{Category, Cop, Severity};
use crate::offense::{Location, Offense};
use crate::source::SourceFile;

// Compile regexes once at startup
static METHOD_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(
        r"^\s*def\s+(?:self\.)?([a-zA-Z_][a-zA-Z0-9_]*[?!=]?|\[\]=?|<=>|<<|>>|==|!=|<=|>=|\+|-|\*|/|%|\*\*|\||&|\^|~|!|<|>)"
    ).unwrap()
});

static VALID_METHOD_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"^[a-z_][a-z0-9_]*[?!=]?$"#).unwrap()
});

static ASSIGNMENT_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"([a-zA-Z_][a-zA-Z0-9_]*)\s*=[^=>~!]"#).unwrap()
});

static VALID_VARIABLE_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"^[a-z_][a-z0-9_]*$"#).unwrap()
});

static CLASS_MODULE_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"^\s*(class|module)\s+([a-zA-Z_][a-zA-Z0-9_]*)"#).unwrap()
});

static CONSTANT_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"(?:^|[^a-zA-Z0-9_])([A-Z][a-zA-Z0-9_]*)\s*=[^=>~!]"#).unwrap()
});

static VALID_PASCAL_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"^[A-Z][a-zA-Z0-9]*$"#).unwrap()
});

static VALID_CONSTANT_PATTERN: Lazy<Regex> = Lazy::new(|| {
    Regex::new(r#"^[A-Z][A-Z0-9_]*$"#).unwrap()
});

/// Checks that method names use snake_case.
///
/// # Examples
///
/// ```ruby
/// # good
/// def some_method
/// def method_name?
/// def method!
/// def []
/// def <=>
///
/// # bad
/// def SomeMethod
/// def methodName
/// ```
pub struct MethodName;

impl Cop for MethodName {
    fn name(&self) -> &str {
        "Naming/MethodName"
    }

    fn category(&self) -> Category {
        Category::Naming
    }

    fn severity(&self) -> Severity {
        Severity::Convention
    }

    fn description(&self) -> &str {
        "Method names should use snake_case"
    }

    fn check(&self, source: &SourceFile) -> Vec<Offense> {
        let mut offenses = Vec::new();

        for (line_num, line) in source.lines.iter().enumerate() {
            let line_number = line_num + 1;

            // Check if this is a method definition
            if let Some(captures) = METHOD_PATTERN.captures(line) {
                if let Some(method_match) = captures.get(1) {
                    let method_name = method_match.as_str();

                    // Calculate column as character position (1-based)
                    let byte_offset = method_match.start();
                    let column = line[..byte_offset].chars().count() + 1;

                    // Skip if inside string or comment
                    if source.in_string_or_comment(line_number, column) {
                        continue;
                    }

                    // Check if it's a special operator method (always valid)
                    let special_methods = [
                        "[]", "[]=", "<=>", "<<", ">>", "==", "!=", "<=", ">=",
                        "+", "-", "*", "/", "%", "**", "|", "&", "^", "~", "!", "<", ">",
                    ];
                    if special_methods.contains(&method_name) {
                        continue;
                    }

                    // Validate snake_case
                    if !VALID_METHOD_PATTERN.is_match(method_name) {
                        offenses.push(Offense::new(
                            self.name(),
                            format!("Method name `{}` should use snake_case", method_name),
                            self.severity(),
                            Location::new(line_number, column, method_name.len()),
                        ));
                    }
                }
            }
        }

        offenses
    }
}

/// Checks that local variable names use snake_case.
///
/// # Examples
///
/// ```ruby
/// # good
/// some_variable = 1
/// variable_name = 2
/// _private = 3
///
/// # bad
/// SomeVariable = 1
/// variableName = 2
/// ```
pub struct VariableName;

impl Cop for VariableName {
    fn name(&self) -> &str {
        "Naming/VariableName"
    }

    fn category(&self) -> Category {
        Category::Naming
    }

    fn severity(&self) -> Severity {
        Severity::Convention
    }

    fn description(&self) -> &str {
        "Variable names should use snake_case"
    }

    fn check(&self, source: &SourceFile) -> Vec<Offense> {
        let mut offenses = Vec::new();

        for (line_num, line) in source.lines.iter().enumerate() {
            let line_number = line_num + 1;

            for captures in ASSIGNMENT_PATTERN.captures_iter(line) {
                if let Some(var_match) = captures.get(1) {
                    let var_name = var_match.as_str();

                    // Calculate column as character position (1-based)
                    let byte_offset = var_match.start();
                    let column = line[..byte_offset].chars().count() + 1;

                    // Skip if inside string or comment
                    if source.in_string_or_comment(line_number, column) {
                        continue;
                    }

                    // Skip constants (names starting with uppercase are constants in Ruby)
                    if var_name.starts_with(|c: char| c.is_uppercase()) {
                        continue;
                    }

                    // Check if preceded by @ or $
                    // Calculate character position before the variable name
                    let chars_before = line[..byte_offset].chars().collect::<Vec<char>>();
                    if let Some(&last_char) = chars_before.last() {
                        if last_char == '@' || last_char == '$' {
                            continue;
                        }
                    }
                    // Check for @@ (class variable)
                    if chars_before.len() >= 2 {
                        let last_two = &chars_before[chars_before.len() - 2..];
                        if last_two == ['@', '@'] {
                            continue;
                        }
                    }

                    // Validate snake_case
                    if !VALID_VARIABLE_PATTERN.is_match(var_name) {
                        offenses.push(Offense::new(
                            self.name(),
                            format!("Variable name `{}` should use snake_case", var_name),
                            self.severity(),
                            Location::new(line_number, column, var_name.len()),
                        ));
                    }
                }
            }
        }

        offenses
    }
}

/// Checks that constants use SCREAMING_SNAKE_CASE and classes/modules use PascalCase.
///
/// # Examples
///
/// ```ruby
/// # good
/// SOME_CONSTANT = 1
/// MAX_VALUE = 100
/// class MyClass
/// module MyModule
///
/// # bad
/// SomeConstant = 1
/// some_constant = 1
/// class myClass
/// module my_module
/// ```
pub struct ConstantName;

impl Cop for ConstantName {
    fn name(&self) -> &str {
        "Naming/ConstantName"
    }

    fn category(&self) -> Category {
        Category::Naming
    }

    fn severity(&self) -> Severity {
        Severity::Convention
    }

    fn description(&self) -> &str {
        "Constants should use SCREAMING_SNAKE_CASE; classes and modules should use PascalCase"
    }

    fn check(&self, source: &SourceFile) -> Vec<Offense> {
        let mut offenses = Vec::new();

        for (line_num, line) in source.lines.iter().enumerate() {
            let line_number = line_num + 1;

            // Check class/module names
            if let Some(captures) = CLASS_MODULE_PATTERN.captures(line) {
                if let Some(name_match) = captures.get(2) {
                    let name = name_match.as_str();

                    // Calculate column as character position (1-based)
                    let byte_offset = name_match.start();
                    let column = line[..byte_offset].chars().count() + 1;

                    // Skip if inside string or comment
                    if source.in_string_or_comment(line_number, column) {
                        continue;
                    }

                    // Validate PascalCase
                    if !VALID_PASCAL_PATTERN.is_match(name) {
                        offenses.push(Offense::new(
                            self.name(),
                            format!(
                                "Class/Module name `{}` should use PascalCase",
                                name
                            ),
                            self.severity(),
                            Location::new(line_number, column, name.len()),
                        ));
                    }
                }
            }

            // Check constant names
            for captures in CONSTANT_PATTERN.captures_iter(line) {
                if let Some(const_match) = captures.get(1) {
                    let const_name = const_match.as_str();

                    // Calculate column as character position (1-based)
                    let byte_offset = const_match.start();
                    let column = line[..byte_offset].chars().count() + 1;

                    // Skip if inside string or comment
                    if source.in_string_or_comment(line_number, column) {
                        continue;
                    }

                    // Check if this is part of a class/module definition (skip those)
                    if CLASS_MODULE_PATTERN.is_match(line) {
                        continue;
                    }

                    // Validate SCREAMING_SNAKE_CASE
                    if !VALID_CONSTANT_PATTERN.is_match(const_name) {
                        offenses.push(Offense::new(
                            self.name(),
                            format!(
                                "Constant name `{}` should use SCREAMING_SNAKE_CASE",
                                const_name
                            ),
                            self.severity(),
                            Location::new(line_number, column, const_name.len()),
                        ));
                    }
                }
            }
        }

        offenses
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;

    fn test_source(content: &str) -> SourceFile {
        SourceFile::from_string(PathBuf::from("test.rb"), content.to_string())
    }

    // MethodName tests
    mod method_name {
        use super::*;

        #[test]
        fn test_valid_snake_case_methods() {
            let source = test_source(
                r#"
def some_method
end

def another_method
end

def method_with_numbers123
end

def _private_method
end
"#,
            );
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Valid snake_case methods should not create offenses");
        }

        #[test]
        fn test_valid_predicate_and_bang_methods() {
            let source = test_source(
                r#"
def valid?
end

def save!
end

def equals=
end
"#,
            );
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Predicate and bang methods should be valid");
        }

        #[test]
        fn test_valid_special_operator_methods() {
            let source = test_source(
                r#"
def []
end

def []=
end

def <=>
end

def <<
end

def >>
end

def ==
end

def +
end

def -
end

def *
end

def **
end
"#,
            );
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Special operator methods should be valid");
        }

        #[test]
        fn test_invalid_camel_case_method() {
            let source = test_source("def someMethod\nend\n");
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("someMethod"));
            assert!(offenses[0].message.contains("snake_case"));
        }

        #[test]
        fn test_invalid_pascal_case_method() {
            let source = test_source("def SomeMethod\nend\n");
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("SomeMethod"));
        }

        #[test]
        fn test_valid_self_methods() {
            let source = test_source(
                r#"
def self.class_method
end

def self.another_class_method
end
"#,
            );
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Class methods with self. should be valid");
        }

        #[test]
        fn test_invalid_self_method() {
            let source = test_source("def self.ClassMethod\nend\n");
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
        }

        #[test]
        fn test_method_in_string_ignored() {
            let source = test_source(r#"x = "def BadMethod""#);
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Methods in strings should be ignored");
        }

        #[test]
        fn test_method_in_comment_ignored() {
            let source = test_source("# def BadMethod\n");
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Methods in comments should be ignored");
        }

        #[test]
        fn test_empty_file() {
            let source = test_source("");
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0);
        }

        #[test]
        fn test_multiple_invalid_methods() {
            let source = test_source(
                r#"
def BadMethod
end

def anotherBad
end

def YetAnother
end
"#,
            );
            let cop = MethodName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 3, "Should detect all invalid method names");
        }
    }

    // VariableName tests
    mod variable_name {
        use super::*;

        #[test]
        fn test_valid_snake_case_variables() {
            let source = test_source(
                r#"
some_variable = 1
another_var = 2
var_with_numbers123 = 3
_private_var = 4
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Valid snake_case variables should not create offenses");
        }

        #[test]
        fn test_invalid_camel_case_variable() {
            let source = test_source("someVariable = 1\n");
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("someVariable"));
            assert!(offenses[0].message.contains("snake_case"));
        }

        #[test]
        fn test_pascal_case_treated_as_constant() {
            // In Ruby, names starting with uppercase are constants, not variables.
            // VariableName cop should skip them (ConstantName cop handles them).
            let source = test_source("SomeVariable = 1\n");
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Uppercase names are constants, not variables");
        }

        #[test]
        fn test_constants_ignored() {
            let source = test_source(
                r#"
SOME_CONSTANT = 1
MAX_VALUE = 100
PI = 3.14
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Constants should be ignored by VariableName cop");
        }

        #[test]
        fn test_instance_variables_ignored() {
            let source = test_source(
                r#"
@instance_var = 1
@BadInstanceVar = 2
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Instance variables should be ignored");
        }

        #[test]
        fn test_class_variables_ignored() {
            let source = test_source(
                r#"
@@class_var = 1
@@BadClassVar = 2
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Class variables should be ignored");
        }

        #[test]
        fn test_global_variables_ignored() {
            let source = test_source(
                r#"
$global_var = 1
$BadGlobalVar = 2
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Global variables should be ignored");
        }

        #[test]
        fn test_equality_operator_not_matched() {
            let source = test_source("if x == 5\nend\n");
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Equality operator should not be matched as assignment");
        }

        #[test]
        fn test_variable_in_string_ignored() {
            let source = test_source(r#"x = "BadVariable = 1""#);
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Variables in strings should be ignored");
        }

        #[test]
        fn test_variable_in_comment_ignored() {
            let source = test_source("# BadVariable = 1\n");
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Variables in comments should be ignored");
        }

        #[test]
        fn test_multiple_invalid_variables() {
            // In Ruby, names starting with uppercase are constants, not variables.
            // Only lowercase-starting camelCase names are flagged.
            let source = test_source(
                r#"
anotherBad = 1
someCamel = 2
also_Bad_Mix = 3
"#,
            );
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 3, "Should detect non-snake_case variable names");
        }

        #[test]
        fn test_empty_file() {
            let source = test_source("");
            let cop = VariableName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0);
        }
    }

    // ConstantName tests
    mod constant_name {
        use super::*;

        #[test]
        fn test_valid_screaming_snake_case_constants() {
            let source = test_source(
                r#"
SOME_CONSTANT = 1
MAX_VALUE = 100
PI = 3.14
CONSTANT_WITH_NUMBERS123 = 5
"#,
            );
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Valid SCREAMING_SNAKE_CASE constants should not create offenses");
        }

        #[test]
        fn test_invalid_pascal_case_constant() {
            let source = test_source("SomeConstant = 1\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("SomeConstant"));
            assert!(offenses[0].message.contains("SCREAMING_SNAKE_CASE"));
        }

        #[test]
        fn test_invalid_camel_case_constant() {
            let source = test_source("SomeValue = 1\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
        }

        #[test]
        fn test_valid_class_names() {
            let source = test_source(
                r#"
class MyClass
end

class AnotherClass
end

class ClassWithNumbers123
end
"#,
            );
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Valid PascalCase class names should not create offenses");
        }

        #[test]
        fn test_valid_module_names() {
            let source = test_source(
                r#"
module MyModule
end

module AnotherModule
end
"#,
            );
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Valid PascalCase module names should not create offenses");
        }

        #[test]
        fn test_invalid_class_name_with_underscore() {
            let source = test_source("class My_Class\nend\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("My_Class"));
            assert!(offenses[0].message.contains("PascalCase"));
        }

        #[test]
        fn test_invalid_module_name_snake_case() {
            let source = test_source("module my_module\nend\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 1);
            assert!(offenses[0].message.contains("my_module"));
        }

        #[test]
        fn test_class_in_string_ignored() {
            let source = test_source(r#"x = "class bad_class""#);
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Classes in strings should be ignored");
        }

        #[test]
        fn test_constant_in_comment_ignored() {
            let source = test_source("# BadConstant = 1\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Constants in comments should be ignored");
        }

        #[test]
        fn test_multiple_invalid_constants() {
            let source = test_source(
                r#"
BadConstant = 1
AnotherBad = 2
class bad_class
end
module Bad_Module
end
"#,
            );
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 4, "Should detect all invalid constant/class/module names");
        }

        #[test]
        fn test_empty_file() {
            let source = test_source("");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0);
        }

        #[test]
        fn test_equality_operator_not_matched() {
            let source = test_source("if CONSTANT == 5\nend\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Equality operator should not be matched");
        }

        #[test]
        fn test_single_letter_constant_valid() {
            let source = test_source("X = 1\n");
            let cop = ConstantName;
            let offenses = cop.check(&source);
            assert_eq!(offenses.len(), 0, "Single uppercase letter constants should be valid");
        }
    }

    // Integration tests
    mod integration {
        use super::*;

        #[test]
        fn test_complex_file_with_multiple_naming_issues() {
            let source = test_source(
                r#"
class MyClass
  CONSTANT = 1
  BadConstant = 2

  def good_method
    local_var = 1
    camelVar = 2
  end

  def BadMethod
    x = 3
  end
end
"#,
            );

            let method_cop = MethodName;
            let var_cop = VariableName;
            let const_cop = ConstantName;

            let method_offenses = method_cop.check(&source);
            let var_offenses = var_cop.check(&source);
            let const_offenses = const_cop.check(&source);

            assert_eq!(method_offenses.len(), 1, "Should find 1 bad method (BadMethod)");
            assert_eq!(var_offenses.len(), 1, "Should find 1 bad variable (camelVar)");
            assert_eq!(const_offenses.len(), 1, "Should find 1 bad constant (BadConstant)");
        }

        #[test]
        fn test_cop_trait_implementations() {
            let method_cop = MethodName;
            assert_eq!(method_cop.name(), "Naming/MethodName");
            assert_eq!(method_cop.category(), Category::Naming);
            assert_eq!(method_cop.severity(), Severity::Convention);

            let var_cop = VariableName;
            assert_eq!(var_cop.name(), "Naming/VariableName");
            assert_eq!(var_cop.category(), Category::Naming);
            assert_eq!(var_cop.severity(), Severity::Convention);

            let const_cop = ConstantName;
            assert_eq!(const_cop.name(), "Naming/ConstantName");
            assert_eq!(const_cop.category(), Category::Naming);
            assert_eq!(const_cop.severity(), Severity::Convention);
        }
    }
}