Skip to main content

sherlock_io/patterns/
swift.rs

1use regex::Regex;
2
3pub struct SwiftPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl SwiftPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // Swift Package Manager
13            Regex::new(r"\.build/").unwrap(),
14            Regex::new(r"\.swiftpm/").unwrap(),
15            Regex::new(r"Packages/").unwrap(),
16            Regex::new(r"Package\.resolved").unwrap(),
17            
18            // Xcode
19            Regex::new(r"\.xcodeproj/").unwrap(),
20            Regex::new(r"\.xcworkspace/").unwrap(),
21            Regex::new(r"DerivedData/").unwrap(),
22            Regex::new(r"\.xcuserstate").unwrap(),
23            Regex::new(r"\.xccheckout").unwrap(),
24            Regex::new(r"\.moved-aside").unwrap(),
25            Regex::new(r"\.xcscmblueprint").unwrap(),
26            Regex::new(r"\.xcscheme").unwrap(),
27            
28            // Build artifacts
29            Regex::new(r"build/").unwrap(),
30            Regex::new(r"\.dSYM/").unwrap(),
31            Regex::new(r"\.app/").unwrap(),
32            Regex::new(r"\.ipa$").unwrap(),
33            Regex::new(r"\.framework/").unwrap(),
34            Regex::new(r"\.xcframework/").unwrap(),
35            
36            // CocoaPods
37            Regex::new(r"Pods/").unwrap(),
38            Regex::new(r"Podfile\.lock").unwrap(),
39            
40            // Carthage
41            Regex::new(r"Carthage/").unwrap(),
42            Regex::new(r"Cartfile\.resolved").unwrap(),
43            
44            // Fastlane
45            Regex::new(r"fastlane/report\.xml").unwrap(),
46            Regex::new(r"fastlane/Preview\.html").unwrap(),
47            Regex::new(r"fastlane/screenshots").unwrap(),
48            Regex::new(r"fastlane/test_output").unwrap(),
49            
50            // Provisioning profiles
51            Regex::new(r"\.mobileprovision$").unwrap(),
52            Regex::new(r"\.provisionprofile$").unwrap(),
53            
54            // Certificates
55            Regex::new(r"\.p12$").unwrap(),
56            Regex::new(r"\.cer$").unwrap(),
57            Regex::new(r"\.certSigningRequest$").unwrap(),
58            
59            // Simulator
60            Regex::new(r"\.xcappdata/").unwrap(),
61            Regex::new(r"\.xclog$").unwrap(),
62            
63            // Archives
64            Regex::new(r"\.xcarchive/").unwrap(),
65            
66            // Instruments
67            Regex::new(r"\.trace/").unwrap(),
68            
69            // Playgrounds
70            Regex::new(r"\.playground/").unwrap(),
71            
72            // Swift compiled modules
73            Regex::new(r"\.swiftmodule/").unwrap(),
74            Regex::new(r"\.swiftdoc$").unwrap(),
75            Regex::new(r"\.swiftsourceinfo$").unwrap(),
76            
77            // Obj-C
78            Regex::new(r"\.pch$").unwrap(),
79            
80            // Core Data
81            Regex::new(r"\.mom$").unwrap(),
82            Regex::new(r"\.momd/").unwrap(),
83            
84            // Interface Builder
85            Regex::new(r"\.nib$").unwrap(),
86            
87            // Asset catalogs
88            Regex::new(r"\.actool$").unwrap(),
89            
90            // Localization
91            Regex::new(r"\.lproj/").unwrap(),
92            
93            // Documentation
94            Regex::new(r"\.docset/").unwrap(),
95            
96            // Backup files
97            Regex::new(r"\.orig$").unwrap(),
98            Regex::new(r"\.rej$").unwrap(),
99            
100            // OS files
101            Regex::new(r"\.DS_Store").unwrap(),
102            Regex::new(r"\.AppleDouble").unwrap(),
103            Regex::new(r"\.LSOverride").unwrap(),
104            
105            // Thumbnails
106            Regex::new(r"\._ ").unwrap(),
107            
108            // Files that might appear in the root of a volume
109            Regex::new(r"\.DocumentRevisions-V100").unwrap(),
110            Regex::new(r"\.fseventsd").unwrap(),
111            Regex::new(r"\.Spotlight-V100").unwrap(),
112            Regex::new(r"\.TemporaryItems").unwrap(),
113            Regex::new(r"\.Trashes").unwrap(),
114            Regex::new(r"\.VolumeIcon\.icns").unwrap(),
115            Regex::new(r"\.com\.apple\.timemachine\.donotpresent").unwrap(),
116            
117            // Directories potentially created on remote AFP share
118            Regex::new(r"\.AppleDB").unwrap(),
119            Regex::new(r"\.AppleDesktop").unwrap(),
120            Regex::new(r"Network Trash Folder").unwrap(),
121            Regex::new(r"Temporary Items").unwrap(),
122            Regex::new(r"\.apdisk").unwrap(),
123            
124            // IDE files
125            Regex::new(r"\.vscode/").unwrap(),
126            Regex::new(r"\.idea/").unwrap(),
127            
128            // Temporary files
129            Regex::new(r"\.tmp$").unwrap(),
130            Regex::new(r"\.swp$").unwrap(),
131            Regex::new(r"\.swo$").unwrap(),
132            Regex::new(r"~$").unwrap(),
133            
134            // Log files
135            Regex::new(r"\.log$").unwrap(),
136            
137            // Crash reports
138            Regex::new(r"\.crash$").unwrap(),
139            
140            // Test results
141            Regex::new(r"\.xcresult/").unwrap(),
142            
143            // Swift format
144            Regex::new(r"\.swiftformat").unwrap(),
145            
146            // SwiftLint
147            Regex::new(r"\.swiftlint\.yml").unwrap(),
148            
149            // Tuist
150            Regex::new(r"\.tuist/").unwrap(),
151            Regex::new(r"Tuist/").unwrap(),
152            
153            // Mint
154            Regex::new(r"\.mint/").unwrap(),
155            
156            // Sourcery
157            Regex::new(r"\.sourcery/").unwrap(),
158            
159            // R.swift
160            Regex::new(r"R\.generated\.swift").unwrap(),
161            
162            // SwiftGen
163            Regex::new(r"\.swiftgen/").unwrap(),
164            
165            // Jazzy
166            Regex::new(r"docs/").unwrap(),
167            
168            // Danger
169            Regex::new(r"Dangerfile").unwrap(),
170            
171            // Bitrise
172            Regex::new(r"bitrise\.yml").unwrap(),
173            
174            // GitHub Actions
175            Regex::new(r"\.github/").unwrap(),
176            
177            // Firebase
178            Regex::new(r"GoogleService-Info\.plist").unwrap(),
179            
180            // TestFlight
181            Regex::new(r"ExportOptions\.plist").unwrap(),
182            
183            // App Store Connect
184            Regex::new(r"metadata/").unwrap(),
185            
186            // Xcode Cloud
187            Regex::new(r"ci_scripts/").unwrap(),
188            
189            // Swift Playgrounds
190            Regex::new(r"\.playgroundbook/").unwrap(),
191            
192            // Reality Composer
193            Regex::new(r"\.rcproject/").unwrap(),
194            
195            // Create ML
196            Regex::new(r"\.mlmodel$").unwrap(),
197            Regex::new(r"\.mlmodelc/").unwrap(),
198            
199            // Metal
200            Regex::new(r"\.metal$").unwrap(),
201            Regex::new(r"\.air$").unwrap(),
202            Regex::new(r"\.metallib$").unwrap(),
203            
204            // SceneKit
205            Regex::new(r"\.scn$").unwrap(),
206            Regex::new(r"\.scnassets/").unwrap(),
207            
208            // SpriteKit
209            Regex::new(r"\.sks$").unwrap(),
210            
211            // Audio
212            Regex::new(r"\.caf$").unwrap(),
213            
214            // Video
215            Regex::new(r"\.mov$").unwrap(),
216            Regex::new(r"\.mp4$").unwrap(),
217            
218            // Images
219            Regex::new(r"\.png$").unwrap(),
220            Regex::new(r"\.jpg$").unwrap(),
221            Regex::new(r"\.jpeg$").unwrap(),
222            Regex::new(r"\.gif$").unwrap(),
223            Regex::new(r"\.tiff$").unwrap(),
224            Regex::new(r"\.svg$").unwrap(),
225            Regex::new(r"\.pdf$").unwrap(),
226            Regex::new(r"\.eps$").unwrap(),
227            
228            // Fonts
229            Regex::new(r"\.ttf$").unwrap(),
230            Regex::new(r"\.otf$").unwrap(),
231            
232            // Data (Note: XML files are legitimate source files and should not be excluded)
233            Regex::new(r"\.json$").unwrap(),
234            Regex::new(r"\.plist$").unwrap(),
235            Regex::new(r"\.csv$").unwrap(),
236            
237            // Backup
238            Regex::new(r"\.bak$").unwrap(),
239            Regex::new(r"\.backup$").unwrap(),
240        ];
241
242        let cache_patterns = vec![
243            // Xcode caches
244            Regex::new(r"DerivedData/").unwrap(),
245            Regex::new(r"\.build/").unwrap(),
246            Regex::new(r"build/").unwrap(),
247            
248            // Swift Package Manager cache
249            Regex::new(r"\.swiftpm/").unwrap(),
250            
251            // CocoaPods cache
252            Regex::new(r"Pods/").unwrap(),
253            
254            // Carthage cache
255            Regex::new(r"Carthage/").unwrap(),
256            
257            // Fastlane cache
258            Regex::new(r"fastlane/report\.xml").unwrap(),
259            Regex::new(r"fastlane/Preview\.html").unwrap(),
260            Regex::new(r"fastlane/screenshots").unwrap(),
261            Regex::new(r"fastlane/test_output").unwrap(),
262            
263            // Test results
264            Regex::new(r"\.xcresult/").unwrap(),
265            
266            // Archives
267            Regex::new(r"\.xcarchive/").unwrap(),
268            
269            // Simulator data
270            Regex::new(r"\.xcappdata/").unwrap(),
271            
272            // Instruments traces
273            Regex::new(r"\.trace/").unwrap(),
274            
275            // Logs
276            Regex::new(r"\.log$").unwrap(),
277            Regex::new(r"\.xclog$").unwrap(),
278            
279            // Crash reports
280            Regex::new(r"\.crash$").unwrap(),
281            
282            // Temporary files
283            Regex::new(r"\.tmp$").unwrap(),
284            Regex::new(r"\.temp$").unwrap(),
285            
286            // OS caches
287            Regex::new(r"\.DS_Store").unwrap(),
288            Regex::new(r"\.AppleDouble").unwrap(),
289            Regex::new(r"\.LSOverride").unwrap(),
290            
291            // IDE caches
292            Regex::new(r"\.vscode/").unwrap(),
293            Regex::new(r"\.idea/").unwrap(),
294            
295            // Editor files
296            Regex::new(r"\.swp$").unwrap(),
297            Regex::new(r"\.swo$").unwrap(),
298            Regex::new(r"~$").unwrap(),
299            
300            // Documentation
301            Regex::new(r"docs/").unwrap(),
302            Regex::new(r"\.docset/").unwrap(),
303            
304            // Tuist cache
305            Regex::new(r"\.tuist/").unwrap(),
306            
307            // Mint cache
308            Regex::new(r"\.mint/").unwrap(),
309            
310            // Sourcery cache
311            Regex::new(r"\.sourcery/").unwrap(),
312            
313            // SwiftGen cache
314            Regex::new(r"\.swiftgen/").unwrap(),
315            
316            // Backup files
317            Regex::new(r"\.orig$").unwrap(),
318            Regex::new(r"\.rej$").unwrap(),
319            Regex::new(r"\.bak$").unwrap(),
320            Regex::new(r"\.backup$").unwrap(),
321        ];
322
323        let extensions = vec![
324            // Swift files
325            "swift".to_string(),
326            
327            // Objective-C files
328            "m".to_string(), "mm".to_string(),
329            "h".to_string(), "hpp".to_string(),
330            
331            // C/C++ files
332            "c".to_string(), "cpp".to_string(),
333            "cc".to_string(), "cxx".to_string(),
334            
335            // Swift dependencies
336            "swiftdeps".to_string(),
337            "swiftmodule".to_string(),
338            "swiftsourceinfo".to_string(),
339            "swiftdoc".to_string(),
340            
341            // Interface Builder
342            "storyboard".to_string(),
343            "xib".to_string(),
344            
345            // Property lists
346            "plist".to_string(),
347            
348            // Entitlements
349            "entitlements".to_string(),
350            
351            // Metal shaders
352            "metal".to_string(),
353            
354            // SceneKit
355            "scn".to_string(),
356            
357            // SpriteKit
358            "sks".to_string(),
359            
360            // Core Data
361            "xcdatamodel".to_string(),
362            "xcdatamodeld".to_string(),
363            "mom".to_string(),
364            "momd".to_string(),
365            
366            // Mapping models
367            "xcmappingmodel".to_string(),
368            
369            // Asset catalogs
370            "xcassets".to_string(),
371            
372            // Localization
373            "strings".to_string(),
374            "stringsdict".to_string(),
375            
376            // Documentation
377            "md".to_string(),
378            "markdown".to_string(),
379            
380            // Configuration
381            "yaml".to_string(),
382            "yml".to_string(),
383            "json".to_string(),
384            "toml".to_string(),
385            
386            // Scripts
387            "sh".to_string(),
388            "py".to_string(),
389            "rb".to_string(),
390            
391            // Certificates
392            "p12".to_string(),
393            "cer".to_string(),
394            "mobileprovision".to_string(),
395            "provisionprofile".to_string(),
396            
397            // Archives
398            "ipa".to_string(),
399            "xcarchive".to_string(),
400            
401            // Playgrounds
402            "playground".to_string(),
403            "playgroundbook".to_string(),
404            
405            // Reality Composer
406            "rcproject".to_string(),
407            
408            // Create ML
409            "mlmodel".to_string(),
410            "mlmodelc".to_string(),
411            
412            // Audio
413            "caf".to_string(),
414            "aiff".to_string(),
415            "wav".to_string(),
416            "mp3".to_string(),
417            "m4a".to_string(),
418            
419            // Video
420            "mov".to_string(),
421            "mp4".to_string(),
422            "m4v".to_string(),
423            "avi".to_string(),
424            
425            // Images
426            "png".to_string(),
427            "jpg".to_string(),
428            "jpeg".to_string(),
429            "gif".to_string(),
430            "tiff".to_string(),
431            "svg".to_string(),
432            "pdf".to_string(),
433            "eps".to_string(),
434            "heic".to_string(),
435            "heif".to_string(),
436            
437            // Fonts
438            "ttf".to_string(),
439            "otf".to_string(),
440            
441            // Data
442            "csv".to_string(),
443            "xml".to_string(),
444            "sqlite".to_string(),
445            "db".to_string(),
446            
447            // Logs
448            "log".to_string(),
449            "crash".to_string(),
450            
451            // Temporary
452            "tmp".to_string(),
453            "temp".to_string(),
454            
455            // Backup
456            "bak".to_string(),
457            "backup".to_string(),
458            "orig".to_string(),
459        ];
460
461        Self {
462            external_patterns,
463            cache_patterns,
464            extensions,
465        }
466    }
467
468    pub fn get_external_patterns(&self) -> &[Regex] {
469        &self.external_patterns
470    }
471
472    pub fn get_cache_patterns(&self) -> &[Regex] {
473        &self.cache_patterns
474    }
475
476    pub fn get_extensions(&self) -> &[String] {
477        &self.extensions
478    }
479
480    pub fn get_script_names() -> Vec<&'static str> {
481        vec![
482            // Swift Package Manager
483            "Package.swift", "Package.resolved",
484            
485            // CocoaPods
486            "Podfile", "Podfile.lock", "*.podspec",
487            
488            // Carthage
489            "Cartfile", "Cartfile.resolved", "Cartfile.private",
490            
491            // Xcode project files
492            "*.xcodeproj", "*.xcworkspace",
493            "project.pbxproj", "*.xcscheme",
494            "*.xcconfig", "*.plist",
495            
496            // Build scripts
497            "build.sh", "build.py", "build.rb",
498            "archive.sh", "deploy.sh", "test.sh",
499            
500            // Fastlane
501            "Fastfile", "Appfile", "Deliverfile",
502            "Gymfile", "Matchfile", "Precheckfile",
503            "Scanfile", "Screengrabfile", "Snapshotfile",
504            
505            // Configuration
506            "Info.plist", "*.entitlements",
507            "GoogleService-Info.plist", "ExportOptions.plist",
508            
509            // Documentation
510            "README.md", "CHANGELOG.md", "LICENSE",
511            "CONTRIBUTING.md", "CODE_OF_CONDUCT.md",
512            
513            // CI/CD
514            ".github/workflows/ios.yml", ".github/workflows/swift.yml",
515            ".travis.yml", ".gitlab-ci.yml", "circle.yml",
516            "bitrise.yml", "azure-pipelines.yml",
517            
518            // Xcode Cloud
519            "ci_scripts/ci_pre_xcodebuild.sh",
520            "ci_scripts/ci_post_xcodebuild.sh",
521            "ci_scripts/ci_post_clone.sh",
522            
523            // Code quality
524            ".swiftlint.yml", ".swiftformat",
525            ".swiftgen.yml", ".sourcery.yml",
526            
527            // Testing
528            "*.xctest", "TestPlans/",
529            
530            // Danger
531            "Dangerfile", "Dangerfile.swift",
532            
533            // Tuist
534            "Project.swift", "Workspace.swift",
535            "Config.swift", "Setup.swift",
536            
537            // Mint
538            "Mintfile",
539            
540            // Jazzy
541            ".jazzy.yaml", ".jazzy.yml",
542            
543            // R.swift
544            "R.generated.swift",
545            
546            // SwiftGen
547            "swiftgen.yml",
548            
549            // Sourcery
550            "sourcery.yml", "*.stencil",
551            
552            // Git
553            ".gitignore", ".gitattributes", ".gitmodules",
554            
555            // Editors
556            ".vscode/", ".idea/", ".sublime-project",
557            
558            // Environment
559            ".env", ".env.local", ".env.example",
560            
561            // Docker
562            "Dockerfile", "docker-compose.yml", ".dockerignore",
563            
564            // Scripts
565            "scripts/", "bin/", "tools/",
566            
567            // Assets
568            "Assets.xcassets/", "*.xcassets",
569            
570            // Localization
571            "*.lproj/", "Localizable.strings",
572            "InfoPlist.strings", "*.stringsdict",
573            
574            // Core Data
575            "*.xcdatamodel", "*.xcdatamodeld",
576            "*.xcmappingmodel",
577            
578            // Interface Builder
579            "*.storyboard", "*.xib",
580            
581            // Metal
582            "*.metal", "*.air", "*.metallib",
583            
584            // SceneKit
585            "*.scn", "*.scnassets/",
586            
587            // SpriteKit
588            "*.sks", "*.atlas/",
589            
590            // Reality Composer
591            "*.rcproject/",
592            
593            // Create ML
594            "*.mlmodel", "*.mlmodelc/",
595            
596            // Playgrounds
597            "*.playground/", "*.playgroundbook/",
598            
599            // Audio
600            "*.caf", "*.aiff", "*.wav", "*.mp3", "*.m4a",
601            
602            // Video
603            "*.mov", "*.mp4", "*.m4v", "*.avi",
604            
605            // Images
606            "*.png", "*.jpg", "*.jpeg", "*.gif",
607            "*.tiff", "*.svg", "*.pdf", "*.eps",
608            "*.heic", "*.heif",
609            
610            // Fonts
611            "*.ttf", "*.otf",
612            
613            // Data
614            "*.json", "*.plist", "*.xml", "*.csv",
615            "*.sqlite", "*.db",
616            
617            // Certificates
618            "*.p12", "*.cer", "*.mobileprovision",
619            "*.provisionprofile", "*.certSigningRequest",
620            
621            // Archives
622            "*.ipa", "*.xcarchive/",
623            
624            // Frameworks
625            "*.framework/", "*.xcframework/",
626            
627            // Libraries
628            "*.a", "*.dylib",
629            
630            // Modules
631            "*.swiftmodule/", "*.swiftdoc",
632            "*.swiftsourceinfo", "*.swiftdeps",
633            
634            // Instruments
635            "*.trace/",
636            
637            // Simulator
638            "*.xcappdata/", "*.xclog",
639            
640            // Test results
641            "*.xcresult/",
642            
643            // Logs
644            "*.log", "*.crash",
645            
646            // Temporary
647            "*.tmp", "*.temp", "*.swp", "*.swo",
648            
649            // Backup
650            "*.bak", "*.backup", "*.orig", "*.rej",
651            
652            // OS
653            ".DS_Store", ".AppleDouble", ".LSOverride",
654            "._*", ".DocumentRevisions-V100",
655            ".fseventsd", ".Spotlight-V100",
656            ".TemporaryItems", ".Trashes",
657            ".VolumeIcon.icns",
658            ".com.apple.timemachine.donotpresent",
659            ".AppleDB", ".AppleDesktop",
660            "Network Trash Folder", "Temporary Items",
661            ".apdisk",
662        ]
663    }
664}