Skip to main content

sherlock_io/patterns/
elixir.rs

1use regex::Regex;
2
3pub struct ElixirPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl ElixirPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // Mix build artifacts
13            Regex::new(r"_build/").unwrap(),
14            Regex::new(r"deps/").unwrap(),
15            Regex::new(r"mix\.lock").unwrap(),
16            
17            // Hex packages
18            Regex::new(r"\.hex/").unwrap(),
19            Regex::new(r"hex_metadata\.config").unwrap(),
20            
21            // Compiled files
22            Regex::new(r"\.beam$").unwrap(),
23            Regex::new(r"\.plt$").unwrap(),
24            
25            // OTP releases
26            Regex::new(r"_rel/").unwrap(),
27            Regex::new(r"rel/").unwrap(),
28            
29            // Documentation
30            Regex::new(r"doc/").unwrap(),
31            Regex::new(r"docs/").unwrap(),
32            
33            // Coverage reports
34            Regex::new(r"cover/").unwrap(),
35            Regex::new(r"coverage/").unwrap(),
36            
37            // Logs
38            Regex::new(r"logs/").unwrap(),
39            Regex::new(r"log/").unwrap(),
40            
41            // Temporary files
42            Regex::new(r"\.tmp/").unwrap(),
43            Regex::new(r"tmp/").unwrap(),
44            
45            // Dialyzer
46            Regex::new(r"\.dialyzer_plt").unwrap(),
47            
48            // Phoenix specific
49            Regex::new(r"priv/static/").unwrap(),
50            Regex::new(r"priv/gettext/").unwrap(),
51            
52            // Node.js artifacts (for Phoenix projects)
53            Regex::new(r"node_modules/").unwrap(),
54            Regex::new(r"package-lock\.json").unwrap(),
55            
56            // Temporary files
57            Regex::new(r"\.swp$").unwrap(),
58            Regex::new(r"\.swo$").unwrap(),
59            Regex::new(r"~$").unwrap(),
60        ];
61
62        let cache_patterns = vec![
63            // Mix cache
64            Regex::new(r"_build/").unwrap(),
65            
66            // Dependencies cache
67            Regex::new(r"deps/").unwrap(),
68            
69            // Hex cache
70            Regex::new(r"\.hex/").unwrap(),
71            
72            // Dialyzer cache
73            Regex::new(r"\.dialyzer_plt").unwrap(),
74            
75            // Coverage cache
76            Regex::new(r"cover/").unwrap(),
77            
78            // Documentation cache
79            Regex::new(r"doc/").unwrap(),
80        ];
81
82        let extensions = vec![
83            // Elixir source files
84            "ex".to_string(),
85            
86            // Elixir script files
87            "exs".to_string(),
88            
89            // Elixir templates
90            "eex".to_string(),
91            "heex".to_string(),
92            "leex".to_string(),
93            
94            // Configuration files
95            "json".to_string(),
96            "yaml".to_string(),
97            "yml".to_string(),
98            
99            // Documentation
100            "md".to_string(),
101            "markdown".to_string(),
102            
103            // Web assets (Phoenix)
104            "js".to_string(),
105            "css".to_string(),
106            "scss".to_string(),
107            "html".to_string(),
108            
109            // Database files
110            "sql".to_string(),
111            
112            // Shell scripts
113            "sh".to_string(),
114        ];
115
116        Self {
117            external_patterns,
118            cache_patterns,
119            extensions,
120        }
121    }
122
123    pub fn get_external_patterns(&self) -> &[Regex] {
124        &self.external_patterns
125    }
126
127    pub fn get_cache_patterns(&self) -> &[Regex] {
128        &self.cache_patterns
129    }
130
131    pub fn get_extensions(&self) -> &[String] {
132        &self.extensions
133    }
134
135    pub fn get_script_names() -> Vec<&'static str> {
136        vec![
137            // Mix files
138            "mix.exs", "mix.lock",
139            
140            // Configuration
141            "config.exs", "dev.exs", "prod.exs", "test.exs",
142            "runtime.exs", "releases.exs",
143            
144            // Phoenix files
145            "phoenix_static_buildpack.config",
146            "elixir_buildpack.config",
147            
148            // OTP applications
149            "rebar.config", "rebar.lock",
150            
151            // Documentation
152            "README.md", "CHANGELOG.md", "LICENSE",
153            
154            // Build scripts
155            "Makefile", "makefile", "build.sh",
156            
157            // CI/CD
158            ".github/workflows/elixir.yml",
159            ".travis.yml", "appveyor.yml",
160            "circle.yml", ".circleci/config.yml",
161            
162            // Git
163            ".gitignore", ".gitattributes",
164            
165            // Editor
166            ".formatter.exs", ".credo.exs",
167            
168            // Deployment
169            "Dockerfile", "docker-compose.yml",
170            "Procfile", "app.json",
171            
172            // Environment
173            ".env", ".env.example",
174            
175            // Database
176            "seeds.exs", "structure.sql",
177            
178            // Tests
179            "test_helper.exs",
180            
181            // Benchmarks
182            "bench.exs", "benchmarks.exs",
183            
184            // Examples
185            "example.exs", "examples.exs",
186            
187            // Assets (Phoenix)
188            "package.json", "webpack.config.js",
189            "brunch-config.js", "postcss.config.js",
190        ]
191    }
192}