ellie_standard_rules/
rules.rs1use crate::Rule;
2use regex::Regex;
3
4lazy_static! {
5 pub static ref CLASS_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
6 warning_id: 0x00,
7 worker: |class_name| {
8 let _ = Regex::new("([a-z][a-z0-9]+[A-Z])+[a-z]+").unwrap();
9 let num_regex = Regex::new("[0-9]+").unwrap();
10 let mut fixed: String;
11 fixed = num_regex.replace_all(&class_name, "").to_string();
12 fixed.get_mut(0..1).map(|s| {
13 s.make_ascii_lowercase();
14 &*s
15 });
16 (fixed == class_name, fixed)
17 }
18 };
19 pub static ref VARIABLE_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
20 warning_id: 0x01,
21 worker: |variable_name| {
22 let _ = Regex::new("\\b([a-z][a-z0-9]+[A-Z])+[a-z0-9]").unwrap();
23 let num_regex = Regex::new("[0-9]+").unwrap();
24 let mut fixed: String;
25 fixed = num_regex.replace_all(&variable_name, "").to_string();
26 fixed.get_mut(0..1).map(|s| {
27 s.make_ascii_lowercase();
28 &*s
29 });
30 (variable_name == fixed, fixed)
31 }
32 };
33 pub static ref FUNCTION_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
34 warning_id: 0x04,
35 worker: |param_name| {
36 let _ = Regex::new("\\b([a-z][a-z0-9]+[A-Z])+[a-z0-9]").unwrap();
37 let num_regex = Regex::new("[0-9]+").unwrap();
38 let mut fixed: String;
39 fixed = num_regex.replace_all(¶m_name, "").to_string();
40 fixed.get_mut(0..1).map(|s| {
41 s.make_ascii_lowercase();
42 &*s
43 });
44 (param_name == fixed, fixed)
45 }
46 };
47 pub static ref FUNCTION_PARAM_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
48 warning_id: 0x02,
49 worker: |param_name| {
50 let _ = Regex::new("\\b([a-z][a-z0-9]+[A-Z])+[a-z0-9]").unwrap();
51 let num_regex = Regex::new("[0-9]+").unwrap();
52 let mut fixed: String;
53 fixed = num_regex.replace_all(¶m_name, "").to_string();
54 fixed.get_mut(0..1).map(|s| {
55 s.make_ascii_lowercase();
56 &*s
57 });
58 (param_name == fixed, fixed)
59 }
60 };
61 pub static ref ENUM_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
62 warning_id: 0x03,
63 worker: |enum_name| {
64 let _ = Regex::new("([a-z][a-z0-9]+[A-Z])+[a-z]+").unwrap();
65 let num_regex = Regex::new("[0-9]+").unwrap();
66 let mut fixed: String;
67 fixed = num_regex.replace_all(&enum_name, "").to_string();
68 fixed.get_mut(0..1).map(|s| {
69 s.make_ascii_lowercase();
70 &*s
71 });
72 (fixed == enum_name, fixed)
73 }
74 };
75 pub static ref ENUM_ITEM_NAMING_ISSUE: Rule<String, (bool, String)> = Rule {
76 warning_id: 0x03,
77 worker: |enum_item_name| {
78 let _ = Regex::new("([a-z][a-z0-9]+[A-Z])+[a-z]+").unwrap();
79 let num_regex = Regex::new("[0-9]+").unwrap();
80 let mut fixed: String;
81 fixed = num_regex.replace_all(&enum_item_name, "").to_string();
82 fixed.get_mut(0..1).map(|s| {
83 s.make_ascii_lowercase();
84 &*s
85 });
86 (fixed == enum_item_name, fixed)
87 }
88 };
89}