Skip to main content

sherlock_io/patterns/
lua.rs

1use regex::Regex;
2
3pub struct LuaPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl LuaPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // LuaRocks artifacts
13            Regex::new(r"\.luarocks/").unwrap(),
14            Regex::new(r"luarocks\.lock").unwrap(),
15            
16            // Compiled Lua files
17            Regex::new(r"\.luac$").unwrap(),
18            
19            // Love2D builds
20            Regex::new(r"\.love$").unwrap(),
21            
22            // OpenResty/Nginx Lua cache
23            Regex::new(r"nginx_tmp/").unwrap(),
24            Regex::new(r"logs/").unwrap(),
25            
26            // Torch/PyTorch Lua artifacts
27            Regex::new(r"\.t7$").unwrap(),
28            
29            // Wireshark Lua artifacts
30            Regex::new(r"\.wslua$").unwrap(),
31            
32            // Redis Lua cache
33            Regex::new(r"dump\.rdb").unwrap(),
34            
35            // Temporary files
36            Regex::new(r"\.tmp/").unwrap(),
37            Regex::new(r"tmp/").unwrap(),
38            Regex::new(r"\.swp$").unwrap(),
39            Regex::new(r"\.swo$").unwrap(),
40            Regex::new(r"~$").unwrap(),
41        ];
42
43        let cache_patterns = vec![
44            // LuaRocks cache
45            Regex::new(r"\.luarocks/").unwrap(),
46            
47            // Compiled cache
48            Regex::new(r"\.luac$").unwrap(),
49            
50            // Love2D cache
51            Regex::new(r"\.love$").unwrap(),
52            
53            // Nginx cache
54            Regex::new(r"nginx_tmp/").unwrap(),
55        ];
56
57        let extensions = vec![
58            // Lua source files
59            "lua".to_string(),
60            
61            // Compiled Lua
62            "luac".to_string(),
63            
64            // Love2D files
65            "love".to_string(),
66            
67            // Configuration files
68            "json".to_string(),
69            "yaml".to_string(),
70            "yml".to_string(),
71            "toml".to_string(),
72            
73            // Documentation
74            "md".to_string(),
75            "rst".to_string(),
76            "txt".to_string(),
77            
78            // Web files (for OpenResty/Nginx)
79            "html".to_string(),
80            "css".to_string(),
81            "js".to_string(),
82            
83            // Scripts
84            "sh".to_string(),
85            
86            // C files (for Lua extensions)
87            "c".to_string(),
88            "h".to_string(),
89        ];
90
91        Self {
92            external_patterns,
93            cache_patterns,
94            extensions,
95        }
96    }
97
98    pub fn get_external_patterns(&self) -> &[Regex] {
99        &self.external_patterns
100    }
101
102    pub fn get_cache_patterns(&self) -> &[Regex] {
103        &self.cache_patterns
104    }
105
106    pub fn get_extensions(&self) -> &[String] {
107        &self.extensions
108    }
109
110    pub fn get_script_names() -> Vec<&'static str> {
111        vec![
112            // LuaRocks files
113            "rockspec", "*.rockspec",
114            
115            // Love2D files
116            "main.lua", "conf.lua",
117            
118            // OpenResty/Nginx files
119            "nginx.conf", "mime.types",
120            
121            // Build files
122            "Makefile", "makefile", "build.sh",
123            
124            // Configuration files
125            "config.lua", "settings.lua",
126            
127            // Documentation
128            "README.md", "CHANGELOG.md", "LICENSE",
129            
130            // CI/CD
131            ".github/workflows/lua.yml",
132            ".travis.yml", "appveyor.yml",
133            "circle.yml", ".circleci/config.yml",
134            
135            // Git
136            ".gitignore", ".gitattributes",
137            
138            // Docker
139            "Dockerfile", "docker-compose.yml",
140            
141            // Environment
142            ".env", ".env.example",
143            
144            // Test files
145            "test.lua", "tests.lua", "spec.lua",
146            
147            // Init files
148            "init.lua", "main.lua",
149            
150            // Common module files
151            "lib.lua", "utils.lua", "helpers.lua",
152            
153            // Game development (Love2D)
154            "game.lua", "player.lua", "enemy.lua",
155            
156            // Web development (OpenResty)
157            "app.lua", "server.lua", "handler.lua",
158            
159            // Wireshark
160            "dissector.lua", "plugin.lua",
161            
162            // Redis
163            "script.lua", "redis.lua",
164        ]
165    }
166}