@raintree-technology/hig-doctor-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +38 -0
- package/dist/audit-generator.d.ts +4 -0
- package/dist/audit.d.ts +39 -0
- package/dist/categorizer.d.ts +16 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +2780 -0
- package/dist/patterns.d.ts +53 -0
- package/dist/scanner.d.ts +26 -0
- package/package.json +58 -0
- package/src/analyze.ts +35 -0
- package/src/audit-generator.test.ts +166 -0
- package/src/audit-generator.ts +294 -0
- package/src/audit.test.ts +121 -0
- package/src/audit.ts +150 -0
- package/src/baseline.test.ts +83 -0
- package/src/baseline.ts +0 -0
- package/src/benchmark.test.ts +29 -0
- package/src/benchmark.ts +354 -0
- package/src/cache.test.ts +64 -0
- package/src/cache.ts +83 -0
- package/src/categorizer.test.ts +51 -0
- package/src/categorizer.ts +98 -0
- package/src/config.test.ts +131 -0
- package/src/config.ts +174 -0
- package/src/engines/ast-tsx.test.ts +54 -0
- package/src/engines/ast-tsx.ts +167 -0
- package/src/engines/swift-structural.test.ts +39 -0
- package/src/engines/swift-structural.ts +171 -0
- package/src/fixes.test.ts +87 -0
- package/src/fixes.ts +136 -0
- package/src/index.ts +80 -0
- package/src/patterns.test.ts +844 -0
- package/src/patterns.ts +1296 -0
- package/src/sarif.test.ts +39 -0
- package/src/sarif.ts +117 -0
- package/src/scanner.test.ts +153 -0
- package/src/scanner.ts +304 -0
package/src/patterns.ts
ADDED
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
// patterns.ts — Universal HIG pattern detection across all frameworks
|
|
2
|
+
// Rules cover Swift, React, Vue, Svelte, Angular, Flutter, Kotlin, Android XML, CSS, HTML.
|
|
3
|
+
// The authoritative rule count is the exported RULE_COUNT (end of file); never
|
|
4
|
+
// hardcode a count in prose — import RULE_COUNT instead.
|
|
5
|
+
export type Severity = "critical" | "serious" | "moderate";
|
|
6
|
+
|
|
7
|
+
// The Apple HIG snapshot this ruleset and the skills corpus were authored
|
|
8
|
+
// against. Stamped into reports, SARIF output, and MCP responses so consumers
|
|
9
|
+
// can judge staleness. Update alongside a corpus re-scan.
|
|
10
|
+
export const HIG_SNAPSHOT_DATE = "2025-02-02";
|
|
11
|
+
|
|
12
|
+
// Which analysis produced a rule's findings. "regex" is the zero-dependency
|
|
13
|
+
// line/document scanner; "swift-structural" is the comment/string-aware Swift
|
|
14
|
+
// structural analyzer; "ast-tsx" is the TypeScript-compiler-backed JSX tier.
|
|
15
|
+
export type Engine = "regex" | "swift-structural" | "ast-tsx";
|
|
16
|
+
|
|
17
|
+
export interface PatternMatch {
|
|
18
|
+
ruleId: string;
|
|
19
|
+
engine: Engine;
|
|
20
|
+
category: string;
|
|
21
|
+
subcategory: string;
|
|
22
|
+
type: "pattern" | "positive" | "concern";
|
|
23
|
+
pattern: string;
|
|
24
|
+
line: number;
|
|
25
|
+
lineContent: string;
|
|
26
|
+
file: string;
|
|
27
|
+
severity?: Severity;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface PatternRule {
|
|
31
|
+
category: string;
|
|
32
|
+
subcategory: string;
|
|
33
|
+
type: "pattern" | "positive" | "concern";
|
|
34
|
+
pattern: string;
|
|
35
|
+
regex: RegExp;
|
|
36
|
+
hig?: string; // per-rule HIG citation override; default derives from subcategory
|
|
37
|
+
fix?: string; // per-rule fix guidance override; default derives from FIX_GUIDANCE
|
|
38
|
+
fileFilter?: RegExp; // only apply to files matching this pattern
|
|
39
|
+
skipInBlock?: RegExp; // skip this rule when inside a CSS block matching this pattern
|
|
40
|
+
scope?: "document"; // match the whole comment-stripped source, not line-by-line.
|
|
41
|
+
// Needed for tags that span lines and for rules that inspect
|
|
42
|
+
// a child/sibling element (e.g. a <video> with a <track>).
|
|
43
|
+
requireAbsent?: RegExp; // document scope only: fire just once, and only if this
|
|
44
|
+
// pattern appears nowhere in the file (file-level signal).
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Severity classification for concern-type rules.
|
|
48
|
+
// Critical = breaks accessibility outright. Serious = significant UX degradation.
|
|
49
|
+
// Everything else defaults to moderate.
|
|
50
|
+
const CRITICAL_CONCERNS = new Set<string>([
|
|
51
|
+
"missing alt",
|
|
52
|
+
"Image without alt",
|
|
53
|
+
"svg without a11y",
|
|
54
|
+
"empty heading",
|
|
55
|
+
"empty button",
|
|
56
|
+
"missing html lang",
|
|
57
|
+
"video without track",
|
|
58
|
+
"blink element",
|
|
59
|
+
"marquee element",
|
|
60
|
+
"user-scalable=no",
|
|
61
|
+
"maximum-scale=1",
|
|
62
|
+
"ImageView without contentDescription",
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
const SERIOUS_CONCERNS = new Set<string>([
|
|
66
|
+
// "onTapGesture without traits", "Image without a11y", and "hover without
|
|
67
|
+
// focus" are deliberately NOT here: they fire heuristically on common,
|
|
68
|
+
// frequently-fine code, so they default to moderate instead of tripping a
|
|
69
|
+
// `--fail-on serious` CI gate.
|
|
70
|
+
"isAccessibilityElement false on interactive",
|
|
71
|
+
"div with onClick no role",
|
|
72
|
+
"span with onClick no role",
|
|
73
|
+
"ambiguous link text",
|
|
74
|
+
"positive tabindex",
|
|
75
|
+
"aria-hidden on focusable",
|
|
76
|
+
"onMouseOver without onFocus",
|
|
77
|
+
"onMouseOut without onBlur",
|
|
78
|
+
"div as button",
|
|
79
|
+
"div as nav/header class",
|
|
80
|
+
"autoplay media",
|
|
81
|
+
"outline none",
|
|
82
|
+
"v-on:click without keyboard",
|
|
83
|
+
"on:click without on:keydown",
|
|
84
|
+
"(click) without (keydown)",
|
|
85
|
+
"clickable without Role",
|
|
86
|
+
"nested touchables",
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
export function severityFor(pattern: string): Severity {
|
|
90
|
+
if (CRITICAL_CONCERNS.has(pattern)) return "critical";
|
|
91
|
+
if (SERIOUS_CONCERNS.has(pattern)) return "serious";
|
|
92
|
+
return "moderate";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// File filter shorthands
|
|
96
|
+
const SWIFT = /\.swift$/;
|
|
97
|
+
const WEB = /\.(tsx|jsx|html?)$/;
|
|
98
|
+
const TSX_JSX = /\.(tsx|jsx)$/;
|
|
99
|
+
const TS_JS = /\.(tsx|jsx|ts|js)$/;
|
|
100
|
+
const VUE = /\.vue$/;
|
|
101
|
+
const SVELTE = /\.svelte$/;
|
|
102
|
+
const ANGULAR = /\.(ts|html)$/;
|
|
103
|
+
const DART = /\.dart$/;
|
|
104
|
+
const KOTLIN = /\.kt$/;
|
|
105
|
+
const ANDROID_XML = /\.xml$/;
|
|
106
|
+
const WEB_ALL = /\.(tsx|jsx|html?|vue|svelte)$/;
|
|
107
|
+
const STYLE_ALL = /\.(css|scss|sass|less)$/;
|
|
108
|
+
|
|
109
|
+
// ════════════════════════════════════════════════════════════════
|
|
110
|
+
// SWIFT / SWIFTUI RULES (~55 rules)
|
|
111
|
+
// ════════════════════════════════════════════════════════════════
|
|
112
|
+
const swiftRules: PatternRule[] = [
|
|
113
|
+
// Layout & Navigation
|
|
114
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "TabView", regex: /\bTabView\b/, fileFilter: SWIFT },
|
|
115
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavigationStack", regex: /\bNavigationStack\b/, fileFilter: SWIFT },
|
|
116
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavigationSplitView", regex: /\bNavigationSplitView\b/, fileFilter: SWIFT },
|
|
117
|
+
{ category: "components-layout", subcategory: "navigation", type: "concern", pattern: "NavigationView (deprecated)", regex: /\bNavigationView\b/, fileFilter: SWIFT },
|
|
118
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavigationLink", regex: /\bNavigationLink\b/, fileFilter: SWIFT },
|
|
119
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "List", regex: /\bList\s*\{/, fileFilter: SWIFT },
|
|
120
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "ScrollView", regex: /\bScrollView\b/, fileFilter: SWIFT },
|
|
121
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "LazyVGrid", regex: /\bLazyVGrid\b/, fileFilter: SWIFT },
|
|
122
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "LazyHGrid", regex: /\bLazyHGrid\b/, fileFilter: SWIFT },
|
|
123
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "GeometryReader", regex: /\bGeometryReader\b/, fileFilter: SWIFT },
|
|
124
|
+
{ category: "components-layout", subcategory: "layout", type: "positive", pattern: "adaptiveLayout", regex: /\.adaptive\(minimum:/, fileFilter: SWIFT },
|
|
125
|
+
|
|
126
|
+
// Color
|
|
127
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcodedColor", regex: /\.foregroundColor\(\.(red|blue|green|yellow|orange|purple|pink|white|black)\)/, fileFilter: SWIFT },
|
|
128
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcodedRGBColor", regex: /Color\(\s*red:/, fileFilter: SWIFT },
|
|
129
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcodedUIColor", regex: /UIColor\(\s*red:/, fileFilter: SWIFT },
|
|
130
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color(uiColor:)", regex: /Color\(\s*uiColor:\s*UIColor\(\s*red:/, fileFilter: SWIFT },
|
|
131
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "semanticColor", regex: /\.(primary|secondary|accentColor)\b/, fileFilter: SWIFT },
|
|
132
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "foregroundStyle", regex: /\.foregroundStyle\(\.(primary|secondary|tertiary|quaternary)\)/, fileFilter: SWIFT },
|
|
133
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "assetCatalogColor", regex: /Color\(\s*"[^"]+"\s*\)/, fileFilter: SWIFT },
|
|
134
|
+
|
|
135
|
+
// Typography
|
|
136
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "dynamicTypeStyle", regex: /\.font\(\.(largeTitle|title|title2|title3|headline|subheadline|body|callout|footnote|caption|caption2)\)/, fileFilter: SWIFT },
|
|
137
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcodedFontSize", regex: /\.font\(\.system\(size:/, fileFilter: SWIFT },
|
|
138
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcodedUIFont", regex: /UIFont\.\s*systemFont\(ofSize:/, fileFilter: SWIFT },
|
|
139
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "scaledMetric", regex: /@ScaledMetric/, fileFilter: SWIFT },
|
|
140
|
+
|
|
141
|
+
// Accessibility
|
|
142
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityLabel", regex: /\.accessibilityLabel\(/, fileFilter: SWIFT },
|
|
143
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityHint", regex: /\.accessibilityHint\(/, fileFilter: SWIFT },
|
|
144
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityHidden", regex: /\.accessibilityHidden\(/, fileFilter: SWIFT },
|
|
145
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityAddTraits", regex: /\.accessibilityAddTraits\(/, fileFilter: SWIFT },
|
|
146
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityValue", regex: /\.accessibilityValue\(/, fileFilter: SWIFT },
|
|
147
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityAction", regex: /\.accessibilityAction\(/, fileFilter: SWIFT },
|
|
148
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "reduceMotion", regex: /accessibilityReduceMotion/, fileFilter: SWIFT },
|
|
149
|
+
// Swift accessibility concerns
|
|
150
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "onTapGesture without traits", regex: /\.onTapGesture\s*\{/, fileFilter: SWIFT },
|
|
151
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "Image without a11y", regex: /\bImage\(\s*systemName:/, fileFilter: SWIFT },
|
|
152
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "isAccessibilityElement false on interactive", regex: /\.isAccessibilityElement\s*=\s*false/, fileFilter: SWIFT },
|
|
153
|
+
|
|
154
|
+
// Dark mode
|
|
155
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "colorScheme", regex: /@Environment\(\\\.colorScheme\)/, fileFilter: SWIFT },
|
|
156
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "preferredColorScheme", regex: /\.preferredColorScheme\(/, fileFilter: SWIFT },
|
|
157
|
+
|
|
158
|
+
// Controls
|
|
159
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Button", regex: /\bButton\s*[{(]/, fileFilter: SWIFT },
|
|
160
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Toggle", regex: /\bToggle\s*[{(]/, fileFilter: SWIFT },
|
|
161
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Picker", regex: /\bPicker\s*[{(]/, fileFilter: SWIFT },
|
|
162
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Slider", regex: /\bSlider\s*[{(]/, fileFilter: SWIFT },
|
|
163
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Stepper", regex: /\bStepper\s*[{(]/, fileFilter: SWIFT },
|
|
164
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "DatePicker", regex: /\bDatePicker\s*[{(]/, fileFilter: SWIFT },
|
|
165
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "ColorPicker", regex: /\bColorPicker\s*[{(]/, fileFilter: SWIFT },
|
|
166
|
+
|
|
167
|
+
// Dialogs
|
|
168
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "sheet", regex: /\.sheet\(/, fileFilter: SWIFT },
|
|
169
|
+
{ category: "components-dialogs", subcategory: "alerts", type: "pattern", pattern: "alert", regex: /\.alert\(/, fileFilter: SWIFT },
|
|
170
|
+
{ category: "components-dialogs", subcategory: "alerts", type: "pattern", pattern: "confirmationDialog", regex: /\.confirmationDialog\(/, fileFilter: SWIFT },
|
|
171
|
+
{ category: "components-dialogs", subcategory: "popover", type: "pattern", pattern: "popover", regex: /\.popover\(/, fileFilter: SWIFT },
|
|
172
|
+
|
|
173
|
+
// Search
|
|
174
|
+
{ category: "components-search", subcategory: "search", type: "pattern", pattern: "searchable", regex: /\.searchable\(/, fileFilter: SWIFT },
|
|
175
|
+
|
|
176
|
+
// Status
|
|
177
|
+
{ category: "components-status", subcategory: "progress", type: "pattern", pattern: "ProgressView", regex: /\bProgressView\b/, fileFilter: SWIFT },
|
|
178
|
+
|
|
179
|
+
// Menus
|
|
180
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "contextMenu", regex: /\.contextMenu\s*\{/, fileFilter: SWIFT },
|
|
181
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "Menu", regex: /\bMenu\s*\{/, fileFilter: SWIFT },
|
|
182
|
+
{ category: "components-menus", subcategory: "toolbar", type: "pattern", pattern: "toolbar", regex: /\.toolbar\s*\{/, fileFilter: SWIFT },
|
|
183
|
+
|
|
184
|
+
// Patterns
|
|
185
|
+
{ category: "patterns", subcategory: "animation", type: "pattern", pattern: "withAnimation", regex: /\bwithAnimation\b/, fileFilter: SWIFT },
|
|
186
|
+
{ category: "patterns", subcategory: "haptics", type: "pattern", pattern: "sensoryFeedback", regex: /\.sensoryFeedback\(/, fileFilter: SWIFT },
|
|
187
|
+
{ category: "patterns", subcategory: "dragDrop", type: "pattern", pattern: "onDrag", regex: /\.onDrag\b/, fileFilter: SWIFT },
|
|
188
|
+
{ category: "patterns", subcategory: "refresh", type: "pattern", pattern: "refreshable", regex: /\.refreshable\b/, fileFilter: SWIFT },
|
|
189
|
+
{ category: "patterns", subcategory: "swipeActions", type: "pattern", pattern: "swipeActions", regex: /\.swipeActions\b/, fileFilter: SWIFT },
|
|
190
|
+
|
|
191
|
+
// Inputs
|
|
192
|
+
{ category: "inputs", subcategory: "gestures", type: "pattern", pattern: "TapGesture", regex: /\.onTapGesture\b/, fileFilter: SWIFT },
|
|
193
|
+
{ category: "inputs", subcategory: "keyboard", type: "pattern", pattern: "keyboardShortcut", regex: /\.keyboardShortcut\(/, fileFilter: SWIFT },
|
|
194
|
+
{ category: "inputs", subcategory: "focus", type: "pattern", pattern: "focusState", regex: /@FocusState\b/, fileFilter: SWIFT },
|
|
195
|
+
|
|
196
|
+
// Technologies
|
|
197
|
+
{ category: "technologies", subcategory: "appIntents", type: "pattern", pattern: "AppIntent", regex: /\bAppIntent\b/, fileFilter: SWIFT },
|
|
198
|
+
{ category: "technologies", subcategory: "swiftData", type: "pattern", pattern: "SwiftData", regex: /import\s+SwiftData/, fileFilter: SWIFT },
|
|
199
|
+
{ category: "technologies", subcategory: "widgets", type: "pattern", pattern: "WidgetKit", regex: /import\s+WidgetKit/, fileFilter: SWIFT },
|
|
200
|
+
{ category: "technologies", subcategory: "activityKit", type: "pattern", pattern: "ActivityKit", regex: /import\s+ActivityKit/, fileFilter: SWIFT },
|
|
201
|
+
{ category: "technologies", subcategory: "healthKit", type: "pattern", pattern: "HealthKit", regex: /import\s+HealthKit/, fileFilter: SWIFT },
|
|
202
|
+
{ category: "technologies", subcategory: "arKit", type: "pattern", pattern: "ARKit", regex: /import\s+ARKit/, fileFilter: SWIFT },
|
|
203
|
+
{ category: "technologies", subcategory: "applePay", type: "pattern", pattern: "PassKit/ApplePay", regex: /import\s+PassKit|PKPaymentButton/, fileFilter: SWIFT },
|
|
204
|
+
{ category: "technologies", subcategory: "signInApple", type: "pattern", pattern: "SignInWithApple", regex: /ASAuthorizationAppleIDButton|SignInWithAppleButton/, fileFilter: SWIFT },
|
|
205
|
+
|
|
206
|
+
// Platforms
|
|
207
|
+
{ category: "platforms", subcategory: "multiplatform", type: "positive", pattern: "conditionalPlatform", regex: /#if\s+(os\(iOS\)|os\(macOS\)|os\(watchOS\)|os\(tvOS\)|os\(visionOS\))/, fileFilter: SWIFT },
|
|
208
|
+
|
|
209
|
+
// UIKit concerns
|
|
210
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "hardcoded CGRect", regex: /CGRect\(\s*x:\s*\d/, fileFilter: SWIFT },
|
|
211
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "ignoresSafeArea", regex: /\.ignoresSafeArea\(/, fileFilter: SWIFT },
|
|
212
|
+
{ category: "patterns", subcategory: "state", type: "concern", pattern: "non-private @State", regex: /@State\b(?!\s+private\b)\s+(?:var|let)\b/, fileFilter: SWIFT },
|
|
213
|
+
];
|
|
214
|
+
|
|
215
|
+
// ════════════════════════════════════════════════════════════════
|
|
216
|
+
// WEB / REACT / NEXT.JS RULES (~100 rules)
|
|
217
|
+
// ════════════════════════════════════════════════════════════════
|
|
218
|
+
const webCodeRules: PatternRule[] = [
|
|
219
|
+
// ── Accessibility: Positives ────────────────────────────────
|
|
220
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-label", regex: /aria-label\s*=/, fileFilter: WEB },
|
|
221
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-describedby", regex: /aria-describedby/, fileFilter: WEB },
|
|
222
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-live", regex: /aria-live/, fileFilter: WEB },
|
|
223
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-expanded", regex: /aria-expanded/, fileFilter: WEB },
|
|
224
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-hidden", regex: /aria-hidden/, fileFilter: WEB },
|
|
225
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-current", regex: /aria-current/, fileFilter: WEB },
|
|
226
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-invalid", regex: /aria-invalid/, fileFilter: WEB },
|
|
227
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-errormessage", regex: /aria-errormessage/, fileFilter: WEB },
|
|
228
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-required", regex: /aria-required/, fileFilter: WEB },
|
|
229
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "role attribute", regex: /role=["']/, fileFilter: WEB },
|
|
230
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "sr-only", regex: /sr-only|visually-hidden|screen-reader/i, fileFilter: /\.(tsx|jsx|html?|css|vue|svelte)$/ },
|
|
231
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "alt text", regex: /\balt=["'][^"']+["']/, fileFilter: WEB_ALL },
|
|
232
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "tabIndex", regex: /tabIndex=\{0\}|tabindex="0"/, fileFilter: WEB_ALL },
|
|
233
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "focus management", regex: /onFocus|onBlur|useRef.*focus/, fileFilter: TS_JS },
|
|
234
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "keyboard handler", regex: /onKeyDown|onKeyUp|onKeyPress/, fileFilter: TSX_JSX },
|
|
235
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "skip link", regex: /skip.*nav|skip.*content|skiplink/i, fileFilter: /\.(tsx|jsx|html?|css|vue|svelte)$/ },
|
|
236
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "htmlFor/for attribute", regex: /htmlFor=|for=["']/, fileFilter: WEB_ALL },
|
|
237
|
+
|
|
238
|
+
// ── Accessibility: Concerns ─────────────────────────────────
|
|
239
|
+
// Negative-attribute checks use a "tempered greedy token" — (?:(?!X)[^>])* —
|
|
240
|
+
// which walks the tag body asserting attribute X never appears before the
|
|
241
|
+
// closing >. A plain lookbehind/lookahead backtracks and matches tags that DO
|
|
242
|
+
// have the attribute (the original bug flagged <img alt="..."> as missing alt).
|
|
243
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "missing alt", regex: /<img\b(?:(?!\balt\s*=)[^>])*>/i, fileFilter: WEB_ALL, scope: "document" },
|
|
244
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "Image without alt", regex: /<Image\b(?:(?!\balt\s*=)[^>])*>/, fileFilter: TSX_JSX, scope: "document" },
|
|
245
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "svg without a11y", regex: /<svg\b(?:(?!aria-label|aria-hidden|\brole\s*=)[^>])*>/, fileFilter: WEB_ALL, scope: "document" },
|
|
246
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "div with onClick no role", regex: /<div\b(?:(?!\brole\s*=)[^>])*\bonClick\b(?:(?!\brole\s*=)[^>])*>/, fileFilter: TSX_JSX, scope: "document" },
|
|
247
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "span with onClick no role", regex: /<span\b(?:(?!\brole\s*=)[^>])*\bonClick\b(?:(?!\brole\s*=)[^>])*>/, fileFilter: TSX_JSX, scope: "document" },
|
|
248
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "ambiguous link text", regex: />\s*(click here|read more|learn more|here|more)\s*</i, fileFilter: WEB_ALL },
|
|
249
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "positive tabindex", regex: /tabIndex=\{[1-9]|tabindex="[1-9]/, fileFilter: WEB_ALL },
|
|
250
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "aria-hidden on focusable", regex: /aria-hidden=["']true["'][^>]*(?:<button|<a\s|<input|tabIndex)/, fileFilter: WEB_ALL },
|
|
251
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "onMouseOver without onFocus", regex: /onMouseOver=(?![^>]*onFocus)/, fileFilter: TSX_JSX },
|
|
252
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "onMouseOut without onBlur", regex: /onMouseOut=(?![^>]*onBlur)/, fileFilter: TSX_JSX },
|
|
253
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "autoFocus", regex: /autoFocus\b|autofocus\b/, fileFilter: WEB_ALL },
|
|
254
|
+
|
|
255
|
+
// ── Heading & Structure ─────────────────────────────────────
|
|
256
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "empty heading", regex: /<h[1-6][^>]*>\s*<\/h[1-6]>/, fileFilter: WEB_ALL, scope: "document" },
|
|
257
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "empty button", regex: /<button[^>]*>\s*<\/button>/, fileFilter: WEB_ALL, scope: "document" },
|
|
258
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "div as button", regex: /<div[^>]*role=["']button["']/, fileFilter: WEB_ALL, scope: "document" },
|
|
259
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "div as nav/header class", regex: /<div[^>]*class(?:Name)?=["'][^"']*\b(nav|header|footer|sidebar)\b/i, fileFilter: WEB_ALL, scope: "document" },
|
|
260
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "missing html lang", regex: /<html(?!\s[^>]*lang=)/, fileFilter: /\.html?$/, scope: "document" },
|
|
261
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "html lang attribute", regex: /<html\s[^>]*lang=["'][a-z]/, fileFilter: /\.html?$/ },
|
|
262
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "landmark main", regex: /<main\b|role=["']main["']/, fileFilter: WEB_ALL },
|
|
263
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "landmark nav", regex: /<nav\b|role=["']navigation["']/, fileFilter: WEB_ALL },
|
|
264
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "landmark banner", regex: /role=["']banner["']/, fileFilter: WEB_ALL },
|
|
265
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "landmark contentinfo", regex: /role=["']contentinfo["']/, fileFilter: WEB_ALL },
|
|
266
|
+
{ category: "foundations", subcategory: "structure", type: "positive", pattern: "heading h1", regex: /<h1\b/, fileFilter: WEB_ALL },
|
|
267
|
+
{ category: "foundations", subcategory: "structure", type: "pattern", pattern: "heading h2", regex: /<h2\b/, fileFilter: WEB_ALL },
|
|
268
|
+
{ category: "foundations", subcategory: "structure", type: "pattern", pattern: "heading h3", regex: /<h3\b/, fileFilter: WEB_ALL },
|
|
269
|
+
|
|
270
|
+
// ── Color system ────────────────────────────────────────────
|
|
271
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "CSS variable color", regex: /var\(--[a-z]/, fileFilter: /\.(tsx|jsx|css|scss|html?|vue|svelte)$/ },
|
|
272
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "semantic text color", regex: /text-(foreground|muted-foreground|primary|secondary|destructive|accent-foreground)/, fileFilter: TSX_JSX },
|
|
273
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "semantic bg color", regex: /bg-(background|muted|accent|card|popover|primary|secondary|destructive)/, fileFilter: TSX_JSX },
|
|
274
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "semantic border color", regex: /border-(border|input|ring)/, fileFilter: TSX_JSX },
|
|
275
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "inline color style", regex: /style=\{?\{[^}]*color:\s*['"]#/, fileFilter: TSX_JSX },
|
|
276
|
+
|
|
277
|
+
// ── Typography ──────────────────────────────────────────────
|
|
278
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "design token font size", regex: /text-(xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)\b/, fileFilter: TSX_JSX },
|
|
279
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "font-weight token", regex: /font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)\b/, fileFilter: TSX_JSX },
|
|
280
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded font-size px", regex: /font-size:\s*\d+px/, fileFilter: /\.(css|scss|tsx|jsx)$/ },
|
|
281
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "rem/em font size", regex: /font-size:\s*[\d.]+r?em/, fileFilter: STYLE_ALL },
|
|
282
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "system font stack", regex: /font-family:.*(-apple-system|BlinkMacSystemFont|system-ui|SF Pro)/i, fileFilter: STYLE_ALL },
|
|
283
|
+
|
|
284
|
+
// ── Dark mode ───────────────────────────────────────────────
|
|
285
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "dark mode class", regex: /\bdark:/, fileFilter: TSX_JSX },
|
|
286
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "prefers-color-scheme", regex: /prefers-color-scheme/, fileFilter: /\.(css|scss|tsx|jsx|ts|js|vue|svelte)$/ },
|
|
287
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "color-scheme property", regex: /color-scheme:\s*(light\s+dark|dark\s+light)/, fileFilter: STYLE_ALL },
|
|
288
|
+
|
|
289
|
+
// ── Responsive / Layout ─────────────────────────────────────
|
|
290
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "responsive breakpoint", regex: /\b(sm:|md:|lg:|xl:|2xl:)/, fileFilter: TSX_JSX },
|
|
291
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "media query", regex: /@media\s*\(/, fileFilter: STYLE_ALL },
|
|
292
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "safe area inset", regex: /safe-area-inset|env\(safe-area/, fileFilter: /\.(css|scss|tsx|jsx)$/ },
|
|
293
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "container query", regex: /@container\b/, fileFilter: STYLE_ALL },
|
|
294
|
+
|
|
295
|
+
// ── Motion ──────────────────────────────────────────────────
|
|
296
|
+
{ category: "foundations", subcategory: "motion", type: "positive", pattern: "prefers-reduced-motion", regex: /prefers-reduced-motion/, fileFilter: /\.(css|scss|tsx|jsx|ts|js|vue|svelte)$/ },
|
|
297
|
+
{ category: "foundations", subcategory: "motion", type: "pattern", pattern: "CSS animation", regex: /@keyframes/, fileFilter: STYLE_ALL },
|
|
298
|
+
{ category: "foundations", subcategory: "motion", type: "pattern", pattern: "CSS transition", regex: /transition:/, fileFilter: STYLE_ALL },
|
|
299
|
+
|
|
300
|
+
// ── Touch targets ───────────────────────────────────────────
|
|
301
|
+
{ category: "foundations", subcategory: "touchTargets", type: "positive", pattern: "min touch target 44px", regex: /min-(width|height):\s*4[4-8]px|min-(w|h)-1[1-2]\b/, fileFilter: /\.(css|scss|tsx|jsx)$/ },
|
|
302
|
+
|
|
303
|
+
// ── Navigation (components-layout) ──────────────────────────
|
|
304
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "nav element", regex: /<nav\b/, fileFilter: WEB_ALL },
|
|
305
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "Link component", regex: /<Link\b/, fileFilter: TSX_JSX },
|
|
306
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "useRouter", regex: /useRouter\b/, fileFilter: TS_JS },
|
|
307
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "usePathname", regex: /usePathname\b/, fileFilter: TS_JS },
|
|
308
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "header element", regex: /<header\b/, fileFilter: WEB_ALL },
|
|
309
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "main element", regex: /<main\b/, fileFilter: WEB_ALL },
|
|
310
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "footer element", regex: /<footer\b/, fileFilter: WEB_ALL },
|
|
311
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "section element", regex: /<section\b/, fileFilter: WEB_ALL },
|
|
312
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "aside element", regex: /<aside\b/, fileFilter: WEB_ALL },
|
|
313
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "article element", regex: /<article\b/, fileFilter: WEB_ALL },
|
|
314
|
+
{ category: "components-layout", subcategory: "layout", type: "positive", pattern: "grid layout", regex: /grid-cols|grid-template/, fileFilter: /\.(tsx|jsx|css|scss)$/ },
|
|
315
|
+
|
|
316
|
+
// ── Controls (components-controls) ──────────────────────────
|
|
317
|
+
{ category: "components-controls", subcategory: "buttons", type: "pattern", pattern: "button element", regex: /<button\b|<Button\b/, fileFilter: WEB_ALL },
|
|
318
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "input element", regex: /<input\b|<Input\b/, fileFilter: WEB_ALL },
|
|
319
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "select element", regex: /<select\b|<Select\b/, fileFilter: WEB_ALL },
|
|
320
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "textarea element", regex: /<textarea\b|<Textarea\b/, fileFilter: WEB_ALL },
|
|
321
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "checkbox/radio", regex: /type=["'](checkbox|radio)["']/, fileFilter: WEB_ALL },
|
|
322
|
+
{ category: "components-controls", subcategory: "inputs", type: "positive", pattern: "label element", regex: /<label\b|<Label\b/, fileFilter: WEB_ALL },
|
|
323
|
+
{ category: "components-controls", subcategory: "toggle", type: "pattern", pattern: "switch/toggle", regex: /<Switch\b|role=["']switch["']/, fileFilter: TSX_JSX },
|
|
324
|
+
|
|
325
|
+
// ── Forms (inputs) ──────────────────────────────────────────
|
|
326
|
+
{ category: "inputs", subcategory: "forms", type: "pattern", pattern: "form element", regex: /<form\b|<Form\b/, fileFilter: WEB_ALL },
|
|
327
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "form validation", regex: /\brequired\b|pattern=|minLength|maxLength/, fileFilter: WEB_ALL },
|
|
328
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "input type email", regex: /type=["']email["']/, fileFilter: WEB_ALL },
|
|
329
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "input type tel", regex: /type=["']tel["']/, fileFilter: WEB_ALL },
|
|
330
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "input type url", regex: /type=["']url["']/, fileFilter: WEB_ALL },
|
|
331
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "input type number", regex: /type=["']number["']/, fileFilter: WEB_ALL },
|
|
332
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "autocomplete attribute", regex: /autocomplete=["']/, fileFilter: WEB_ALL },
|
|
333
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "fieldset element", regex: /<fieldset\b/, fileFilter: WEB_ALL },
|
|
334
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "legend element", regex: /<legend\b/, fileFilter: WEB_ALL },
|
|
335
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "placeholder text", regex: /placeholder=["']/, fileFilter: WEB_ALL },
|
|
336
|
+
|
|
337
|
+
// ── Dialogs (components-dialogs) ────────────────────────────
|
|
338
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "dialog element", regex: /<dialog\b|<Dialog\b/, fileFilter: WEB_ALL },
|
|
339
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "modal/sheet", regex: /<Modal\b|<Sheet\b|<Drawer\b/, fileFilter: TSX_JSX },
|
|
340
|
+
{ category: "components-dialogs", subcategory: "alerts", type: "pattern", pattern: "alert dialog", regex: /<AlertDialog\b|role=["']alertdialog["']/, fileFilter: TSX_JSX },
|
|
341
|
+
{ category: "components-dialogs", subcategory: "popover", type: "pattern", pattern: "popover", regex: /<Popover\b/, fileFilter: TSX_JSX },
|
|
342
|
+
{ category: "components-dialogs", subcategory: "toast", type: "pattern", pattern: "toast/notification", regex: /<Toast\b|toast\(|<Toaster\b|<Sonner\b/, fileFilter: TSX_JSX },
|
|
343
|
+
{ category: "components-dialogs", subcategory: "tooltip", type: "pattern", pattern: "tooltip", regex: /<Tooltip\b|role=["']tooltip["']/, fileFilter: WEB_ALL },
|
|
344
|
+
|
|
345
|
+
// ── Search (components-search) ──────────────────────────────
|
|
346
|
+
{ category: "components-search", subcategory: "search", type: "pattern", pattern: "search input", regex: /type=["']search["']/, fileFilter: WEB_ALL },
|
|
347
|
+
{ category: "components-search", subcategory: "search", type: "pattern", pattern: "search role", regex: /role=["']search["']/, fileFilter: WEB_ALL },
|
|
348
|
+
|
|
349
|
+
// ── Menus (components-menus) ────────────────────────────────
|
|
350
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "dropdown menu", regex: /<DropdownMenu\b/, fileFilter: TSX_JSX },
|
|
351
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "context menu", regex: /<ContextMenu\b|onContextMenu/, fileFilter: TSX_JSX },
|
|
352
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "menu role", regex: /role=["']menu["']|role=["']menubar["']/, fileFilter: WEB_ALL },
|
|
353
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "menuitem role", regex: /role=["']menuitem["']/, fileFilter: WEB_ALL },
|
|
354
|
+
|
|
355
|
+
// ── Status (components-status) ──────────────────────────────
|
|
356
|
+
{ category: "components-status", subcategory: "progress", type: "pattern", pattern: "progress bar", regex: /<progress\b|<Progress\b|role=["']progressbar["']/, fileFilter: WEB_ALL },
|
|
357
|
+
{ category: "components-status", subcategory: "loading", type: "pattern", pattern: "loading state", regex: /isLoading|loading\s*[=:]|<Skeleton\b|<Spinner\b/, fileFilter: TS_JS },
|
|
358
|
+
{ category: "components-status", subcategory: "loading", type: "pattern", pattern: "aria-busy", regex: /aria-busy/, fileFilter: WEB_ALL },
|
|
359
|
+
|
|
360
|
+
// ── Content (components-content) ────────────────────────────
|
|
361
|
+
{ category: "components-content", subcategory: "images", type: "pattern", pattern: "Next Image", regex: /<Image\b.*\bsrc=/, fileFilter: TSX_JSX },
|
|
362
|
+
{ category: "components-content", subcategory: "tables", type: "pattern", pattern: "table element", regex: /<table\b|<Table\b/, fileFilter: WEB_ALL },
|
|
363
|
+
{ category: "components-content", subcategory: "accordion", type: "pattern", pattern: "accordion", regex: /<Accordion\b/, fileFilter: TSX_JSX },
|
|
364
|
+
{ category: "components-content", subcategory: "cards", type: "pattern", pattern: "card component", regex: /<Card\b/, fileFilter: TSX_JSX },
|
|
365
|
+
{ category: "components-content", subcategory: "lists", type: "pattern", pattern: "list elements", regex: /<ul\b|<ol\b|<dl\b/, fileFilter: WEB_ALL },
|
|
366
|
+
{ category: "components-content", subcategory: "details", type: "pattern", pattern: "details/summary", regex: /<details\b|<summary\b/, fileFilter: WEB_ALL },
|
|
367
|
+
|
|
368
|
+
// ── Patterns ────────────────────────────────────────────────
|
|
369
|
+
{ category: "patterns", subcategory: "animation", type: "pattern", pattern: "framer motion", regex: /framer-motion|motion\.[a-z]/, fileFilter: TS_JS },
|
|
370
|
+
{ category: "patterns", subcategory: "seo", type: "positive", pattern: "metadata/head", regex: /export.*metadata|<Head\b|<title\b/, fileFilter: TS_JS },
|
|
371
|
+
{ category: "patterns", subcategory: "errorHandling", type: "positive", pattern: "error boundary", regex: /ErrorBoundary|error\.tsx/, fileFilter: TS_JS },
|
|
372
|
+
{ category: "patterns", subcategory: "i18n", type: "positive", pattern: "i18n/l10n", regex: /useTranslation|i18n|intl|formatMessage|<FormattedMessage/, fileFilter: TS_JS },
|
|
373
|
+
|
|
374
|
+
// ── Technologies ────────────────────────────────────────────
|
|
375
|
+
{ category: "technologies", subcategory: "analytics", type: "pattern", pattern: "analytics", regex: /@vercel\/analytics|gtag|GoogleAnalytics/, fileFilter: TS_JS },
|
|
376
|
+
|
|
377
|
+
// ── Media accessibility ─────────────────────────────────────
|
|
378
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "video without track", regex: /<video\b(?:(?!<\/video>|<track\b)[\s\S])*?<\/video>/i, fileFilter: WEB_ALL, scope: "document" },
|
|
379
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "autoplay media", regex: /\bauto[Pp]lay\b(?!\s*=\s*\{?\s*['"]?false)/, fileFilter: WEB_ALL },
|
|
380
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "blink element", regex: /<blink\b/, fileFilter: WEB_ALL },
|
|
381
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "marquee element", regex: /<marquee\b/, fileFilter: WEB_ALL },
|
|
382
|
+
|
|
383
|
+
// ── Viewport concerns ───────────────────────────────────────
|
|
384
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "user-scalable=no", regex: /user-scalable\s*=\s*no/, fileFilter: WEB_ALL },
|
|
385
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "maximum-scale=1", regex: /maximum-scale\s*=\s*1\b/, fileFilter: WEB_ALL },
|
|
386
|
+
];
|
|
387
|
+
|
|
388
|
+
// ════════════════════════════════════════════════════════════════
|
|
389
|
+
// CSS-SPECIFIC RULES (~40 rules)
|
|
390
|
+
// ════════════════════════════════════════════════════════════════
|
|
391
|
+
const cssRules: PatternRule[] = [
|
|
392
|
+
// Color
|
|
393
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "CSS custom property def", regex: /--[a-z][\w-]*:\s*/, fileFilter: STYLE_ALL },
|
|
394
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded hex in CSS", regex: /(?:^|[\s;{])(?:color|background(?:-color)?|border(?:-color)?):\s*#[0-9a-fA-F]{3,8}\b/, fileFilter: STYLE_ALL },
|
|
395
|
+
|
|
396
|
+
// Typography
|
|
397
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "clamp font size", regex: /font-size:\s*clamp\(/, fileFilter: STYLE_ALL },
|
|
398
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "font-size below 12px", regex: /font-size:\s*(1[01]|[0-9])px\b/, fileFilter: STYLE_ALL },
|
|
399
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "text-align justify", regex: /text-align:\s*justify/, fileFilter: STYLE_ALL },
|
|
400
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "line-height below 1.2", regex: /line-height:\s*(0\.\d+|1\.[01]\d*)\s*[;}]/, fileFilter: STYLE_ALL },
|
|
401
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "max-width on text", regex: /max-width:.*ch\b/, fileFilter: STYLE_ALL },
|
|
402
|
+
|
|
403
|
+
// Accessibility
|
|
404
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "focus-visible", regex: /:focus-visible/, fileFilter: STYLE_ALL },
|
|
405
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "focus ring styles", regex: /outline.*focus|ring-/, fileFilter: STYLE_ALL },
|
|
406
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "high contrast", regex: /forced-colors|high-contrast|prefers-contrast/, fileFilter: STYLE_ALL },
|
|
407
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "outline none", regex: /outline:\s*(none|0)\b/, fileFilter: STYLE_ALL, skipInBlock: /(:focus:not\(:focus-visible\))|(@media\s+print)/ },
|
|
408
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "hover without focus", regex: /:hover\b/, fileFilter: STYLE_ALL, scope: "document", requireAbsent: /:focus/ },
|
|
409
|
+
|
|
410
|
+
// Layout
|
|
411
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "print styles", regex: /@media\s+print/, fileFilter: STYLE_ALL },
|
|
412
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "logical properties", regex: /margin-inline|padding-inline|border-inline|inset-inline/, fileFilter: STYLE_ALL },
|
|
413
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "flexbox gap", regex: /\bgap:\s*/, fileFilter: STYLE_ALL },
|
|
414
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "aspect-ratio", regex: /aspect-ratio:/, fileFilter: STYLE_ALL },
|
|
415
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "overflow hidden on body", regex: /body\s*\{[^}]*overflow:\s*hidden/, fileFilter: STYLE_ALL },
|
|
416
|
+
|
|
417
|
+
// Touch targets
|
|
418
|
+
{ category: "foundations", subcategory: "touchTargets", type: "positive", pattern: "touch target sizing", regex: /min-(width|height):\s*4[4-8]px/, fileFilter: STYLE_ALL },
|
|
419
|
+
|
|
420
|
+
// z-index
|
|
421
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "extreme z-index", regex: /z-index:\s*[1-9]\d{3,}/, fileFilter: STYLE_ALL },
|
|
422
|
+
|
|
423
|
+
// !important
|
|
424
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "!important usage", regex: /!important/, fileFilter: STYLE_ALL, skipInBlock: /@media\s+print|prefers-reduced-motion/ },
|
|
425
|
+
|
|
426
|
+
// Scrollbar
|
|
427
|
+
{ category: "foundations", subcategory: "layout", type: "pattern", pattern: "custom scrollbar", regex: /-webkit-scrollbar|scrollbar-width/, fileFilter: STYLE_ALL },
|
|
428
|
+
|
|
429
|
+
// i18n / RTL
|
|
430
|
+
{ category: "foundations", subcategory: "i18n", type: "positive", pattern: "RTL direction", regex: /direction:\s*rtl|\[dir=["']rtl["']\]/, fileFilter: STYLE_ALL },
|
|
431
|
+
{ category: "foundations", subcategory: "i18n", type: "positive", pattern: "logical text-align", regex: /text-align:\s*(start|end)\b/, fileFilter: STYLE_ALL },
|
|
432
|
+
{ category: "foundations", subcategory: "i18n", type: "positive", pattern: "logical margin/padding", regex: /margin-inline-start|margin-inline-end|padding-inline-start|padding-inline-end/, fileFilter: STYLE_ALL },
|
|
433
|
+
{ category: "foundations", subcategory: "i18n", type: "concern", pattern: "physical text-align", regex: /text-align:\s*(left|right)\b/, fileFilter: STYLE_ALL },
|
|
434
|
+
];
|
|
435
|
+
|
|
436
|
+
// ════════════════════════════════════════════════════════════════
|
|
437
|
+
// VUE RULES (~25 rules)
|
|
438
|
+
// ════════════════════════════════════════════════════════════════
|
|
439
|
+
const vueRules: PatternRule[] = [
|
|
440
|
+
// Accessibility positives
|
|
441
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "v-bind aria-label", regex: /:?aria-label=|v-bind:aria-label/, fileFilter: VUE },
|
|
442
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "v-bind aria-describedby", regex: /:?aria-describedby=|v-bind:aria-describedby/, fileFilter: VUE },
|
|
443
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "v-bind aria-expanded", regex: /:?aria-expanded=|v-bind:aria-expanded/, fileFilter: VUE },
|
|
444
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "v-bind role", regex: /:?role=|v-bind:role/, fileFilter: VUE },
|
|
445
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "v-bind alt", regex: /:?alt=|v-bind:alt/, fileFilter: VUE },
|
|
446
|
+
// Accessibility concerns
|
|
447
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "v-on:click without keyboard", regex: /v-on:click=|@click=(?![^>]*(?:@keydown|@keyup|v-on:keydown|v-on:keyup))/, fileFilter: VUE },
|
|
448
|
+
// Navigation
|
|
449
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "router-link", regex: /<router-link\b/, fileFilter: VUE },
|
|
450
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NuxtLink", regex: /<NuxtLink\b/, fileFilter: VUE },
|
|
451
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "useRouter (Vue)", regex: /useRouter\(\)/, fileFilter: VUE },
|
|
452
|
+
// Semantic elements
|
|
453
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "nav in template", regex: /<nav\b/, fileFilter: VUE },
|
|
454
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "header in template", regex: /<header\b/, fileFilter: VUE },
|
|
455
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "main in template", regex: /<main\b/, fileFilter: VUE },
|
|
456
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "footer in template", regex: /<footer\b/, fileFilter: VUE },
|
|
457
|
+
// Dark mode
|
|
458
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "Vue dark class", regex: /class="[^"]*dark:|:class="[^"]*dark/, fileFilter: VUE },
|
|
459
|
+
// Controls
|
|
460
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "v-model", regex: /v-model=/, fileFilter: VUE },
|
|
461
|
+
// Forms
|
|
462
|
+
{ category: "inputs", subcategory: "forms", type: "pattern", pattern: "Vue form", regex: /<form\b/, fileFilter: VUE },
|
|
463
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "Vue form validation", regex: /required\b|v-validate|@submit\.prevent/, fileFilter: VUE },
|
|
464
|
+
// Transitions
|
|
465
|
+
{ category: "patterns", subcategory: "animation", type: "pattern", pattern: "Vue transition", regex: /<transition\b|<Transition\b/, fileFilter: VUE },
|
|
466
|
+
// i18n
|
|
467
|
+
{ category: "patterns", subcategory: "i18n", type: "positive", pattern: "Vue i18n", regex: /\$t\(|useI18n|vue-i18n/, fileFilter: VUE },
|
|
468
|
+
];
|
|
469
|
+
|
|
470
|
+
// ════════════════════════════════════════════════════════════════
|
|
471
|
+
// SVELTE RULES (~20 rules)
|
|
472
|
+
// ════════════════════════════════════════════════════════════════
|
|
473
|
+
const svelteRules: PatternRule[] = [
|
|
474
|
+
// Accessibility
|
|
475
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-label (Svelte)", regex: /aria-label=/, fileFilter: SVELTE },
|
|
476
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "aria-describedby (Svelte)", regex: /aria-describedby=/, fileFilter: SVELTE },
|
|
477
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "role (Svelte)", regex: /role=["']/, fileFilter: SVELTE },
|
|
478
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "on:click without on:keydown", regex: /on:click=(?![^>]*on:key(down|up)=)/, fileFilter: SVELTE },
|
|
479
|
+
// Navigation
|
|
480
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "SvelteKit link", regex: /<a\s[^>]*href=["']\//, fileFilter: SVELTE },
|
|
481
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "nav (Svelte)", regex: /<nav\b/, fileFilter: SVELTE },
|
|
482
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "header (Svelte)", regex: /<header\b/, fileFilter: SVELTE },
|
|
483
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "main (Svelte)", regex: /<main\b/, fileFilter: SVELTE },
|
|
484
|
+
// Dark mode
|
|
485
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "Svelte dark class", regex: /class:dark|class="[^"]*dark:/, fileFilter: SVELTE },
|
|
486
|
+
// Motion
|
|
487
|
+
{ category: "foundations", subcategory: "motion", type: "positive", pattern: "Svelte reduced motion", regex: /prefersReducedMotion|prefers-reduced-motion/, fileFilter: SVELTE },
|
|
488
|
+
{ category: "patterns", subcategory: "animation", type: "pattern", pattern: "Svelte transition", regex: /transition:|in:|out:/, fileFilter: SVELTE },
|
|
489
|
+
// Forms
|
|
490
|
+
{ category: "inputs", subcategory: "forms", type: "pattern", pattern: "Svelte form", regex: /<form\b/, fileFilter: SVELTE },
|
|
491
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "Svelte bind:value", regex: /bind:value=/, fileFilter: SVELTE },
|
|
492
|
+
// i18n
|
|
493
|
+
{ category: "patterns", subcategory: "i18n", type: "positive", pattern: "Svelte i18n", regex: /svelte-i18n|\$_\(|i18n/, fileFilter: SVELTE },
|
|
494
|
+
];
|
|
495
|
+
|
|
496
|
+
// ════════════════════════════════════════════════════════════════
|
|
497
|
+
// ANGULAR RULES (~25 rules)
|
|
498
|
+
// ════════════════════════════════════════════════════════════════
|
|
499
|
+
const angularRules: PatternRule[] = [
|
|
500
|
+
// Accessibility
|
|
501
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "[attr.aria-label]", regex: /\[attr\.aria-label\]=/, fileFilter: ANGULAR },
|
|
502
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "[attr.aria-describedby]", regex: /\[attr\.aria-describedby\]=/, fileFilter: ANGULAR },
|
|
503
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "[attr.role]", regex: /\[attr\.role\]=/, fileFilter: ANGULAR },
|
|
504
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "Angular CDK a11y", regex: /cdkTrapFocus|cdkFocusInitial|cdkMonitorSubtreeFocus|A11yModule/, fileFilter: ANGULAR },
|
|
505
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "(click) without (keydown)", regex: /\(click\)=(?![^>]*\(keydown\)=)/, fileFilter: ANGULAR },
|
|
506
|
+
// Navigation
|
|
507
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "routerLink", regex: /routerLink=/, fileFilter: ANGULAR },
|
|
508
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "router-outlet", regex: /<router-outlet/, fileFilter: ANGULAR },
|
|
509
|
+
// Angular Material
|
|
510
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "mat-button", regex: /mat-button|matButton/, fileFilter: ANGULAR },
|
|
511
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "mat-form-field", regex: /mat-form-field|matFormField/, fileFilter: ANGULAR },
|
|
512
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "mat-input", regex: /matInput/, fileFilter: ANGULAR },
|
|
513
|
+
{ category: "components-controls", subcategory: "toggle", type: "pattern", pattern: "mat-slide-toggle", regex: /mat-slide-toggle/, fileFilter: ANGULAR },
|
|
514
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "mat-dialog", regex: /MatDialog|mat-dialog/, fileFilter: ANGULAR },
|
|
515
|
+
{ category: "components-content", subcategory: "tables", type: "pattern", pattern: "mat-table", regex: /mat-table|matTable/, fileFilter: ANGULAR },
|
|
516
|
+
// Forms
|
|
517
|
+
{ category: "inputs", subcategory: "forms", type: "pattern", pattern: "Angular form", regex: /\[formGroup\]=|formControlName=|ngModel/, fileFilter: ANGULAR },
|
|
518
|
+
{ category: "inputs", subcategory: "forms", type: "positive", pattern: "Angular validation", regex: /Validators\.|required|minlength|maxlength/, fileFilter: ANGULAR },
|
|
519
|
+
// i18n
|
|
520
|
+
{ category: "patterns", subcategory: "i18n", type: "positive", pattern: "Angular i18n", regex: /i18n\b|@angular\/localize|translate/, fileFilter: ANGULAR },
|
|
521
|
+
// Dark mode
|
|
522
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "Angular dark theme", regex: /dark-theme|\.dark\b/, fileFilter: ANGULAR },
|
|
523
|
+
];
|
|
524
|
+
|
|
525
|
+
// ════════════════════════════════════════════════════════════════
|
|
526
|
+
// KOTLIN / JETPACK COMPOSE RULES (~30 rules)
|
|
527
|
+
// ════════════════════════════════════════════════════════════════
|
|
528
|
+
const kotlinRules: PatternRule[] = [
|
|
529
|
+
// Accessibility
|
|
530
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "contentDescription", regex: /contentDescription\s*=/, fileFilter: KOTLIN },
|
|
531
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "semantics modifier", regex: /Modifier\.semantics/, fileFilter: KOTLIN },
|
|
532
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "clearAndSetSemantics", regex: /clearAndSetSemantics/, fileFilter: KOTLIN },
|
|
533
|
+
// Catches both the trailing-lambda form `Modifier.clickable { }` (which has no
|
|
534
|
+
// way to pass a role and is therefore always a concern) and the parenthesized
|
|
535
|
+
// `Modifier.clickable(...)` form when no role argument is present.
|
|
536
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "clickable without Role", regex: /Modifier\.clickable\s*(\{|\((?![^)]*role\s*=))/, fileFilter: KOTLIN },
|
|
537
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "testTag", regex: /testTag\s*=/, fileFilter: KOTLIN },
|
|
538
|
+
// Color
|
|
539
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "MaterialTheme colorScheme", regex: /MaterialTheme\.colorScheme/, fileFilter: KOTLIN },
|
|
540
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color(0x)", regex: /Color\(0x[0-9a-fA-F]+\)/, fileFilter: KOTLIN },
|
|
541
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color.Red/Blue", regex: /Color\.(Red|Blue|Green|Yellow|White|Black|Gray|Cyan|Magenta)\b/, fileFilter: KOTLIN },
|
|
542
|
+
// Typography
|
|
543
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "MaterialTheme typography", regex: /MaterialTheme\.typography/, fileFilter: KOTLIN },
|
|
544
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded fontSize", regex: /fontSize\s*=\s*\d+\.sp/, fileFilter: KOTLIN },
|
|
545
|
+
// Dark mode
|
|
546
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "isSystemInDarkTheme", regex: /isSystemInDarkTheme\(\)/, fileFilter: KOTLIN },
|
|
547
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "darkColorScheme", regex: /darkColorScheme\b/, fileFilter: KOTLIN },
|
|
548
|
+
// Layout
|
|
549
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavigationBar", regex: /\bNavigationBar\b/, fileFilter: KOTLIN },
|
|
550
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavHost", regex: /\bNavHost\b/, fileFilter: KOTLIN },
|
|
551
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "BottomNavigation", regex: /\bBottomNavigation\b/, fileFilter: KOTLIN },
|
|
552
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "Scaffold", regex: /\bScaffold\s*\(/, fileFilter: KOTLIN },
|
|
553
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "LazyColumn", regex: /\bLazyColumn\b/, fileFilter: KOTLIN },
|
|
554
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "LazyRow", regex: /\bLazyRow\b/, fileFilter: KOTLIN },
|
|
555
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "LazyVerticalGrid", regex: /\bLazyVerticalGrid\b/, fileFilter: KOTLIN },
|
|
556
|
+
// Controls
|
|
557
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Compose Button", regex: /\bButton\s*\(/, fileFilter: KOTLIN },
|
|
558
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "TextField", regex: /\bTextField\s*\(|OutlinedTextField\s*\(/, fileFilter: KOTLIN },
|
|
559
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Compose Switch", regex: /\bSwitch\s*\(/, fileFilter: KOTLIN },
|
|
560
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Compose Checkbox", regex: /\bCheckbox\s*\(/, fileFilter: KOTLIN },
|
|
561
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "Compose Slider", regex: /\bSlider\s*\(/, fileFilter: KOTLIN },
|
|
562
|
+
// Dialogs
|
|
563
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "AlertDialog (Compose)", regex: /\bAlertDialog\s*\(/, fileFilter: KOTLIN },
|
|
564
|
+
{ category: "components-dialogs", subcategory: "modals", type: "pattern", pattern: "BottomSheet", regex: /BottomSheet|ModalBottomSheet/, fileFilter: KOTLIN },
|
|
565
|
+
// Search
|
|
566
|
+
{ category: "components-search", subcategory: "search", type: "pattern", pattern: "SearchBar (Compose)", regex: /\bSearchBar\s*\(/, fileFilter: KOTLIN },
|
|
567
|
+
// Status
|
|
568
|
+
{ category: "components-status", subcategory: "progress", type: "pattern", pattern: "CircularProgress", regex: /CircularProgressIndicator|LinearProgressIndicator/, fileFilter: KOTLIN },
|
|
569
|
+
];
|
|
570
|
+
|
|
571
|
+
// ════════════════════════════════════════════════════════════════
|
|
572
|
+
// ANDROID XML RULES (~20 rules)
|
|
573
|
+
// ════════════════════════════════════════════════════════════════
|
|
574
|
+
const androidXmlRules: PatternRule[] = [
|
|
575
|
+
// Accessibility
|
|
576
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "android:contentDescription", regex: /android:contentDescription=/, fileFilter: ANDROID_XML },
|
|
577
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "ImageView without contentDescription", regex: /<ImageView(?![^>]*contentDescription=)/, fileFilter: ANDROID_XML },
|
|
578
|
+
{ category: "foundations", subcategory: "accessibility", type: "pattern", pattern: "importantForAccessibility", regex: /android:importantForAccessibility/, fileFilter: ANDROID_XML },
|
|
579
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "android:labelFor", regex: /android:labelFor=/, fileFilter: ANDROID_XML },
|
|
580
|
+
// Color / resources
|
|
581
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "@color/ resource", regex: /@color\//, fileFilter: ANDROID_XML },
|
|
582
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded color in XML", regex: /android:(?:text|background)Color=["']#/, fileFilter: ANDROID_XML },
|
|
583
|
+
// Typography
|
|
584
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "sp text size", regex: /android:textSize=["']\d+sp/, fileFilter: ANDROID_XML },
|
|
585
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "dp text size", regex: /android:textSize=["']\d+dp/, fileFilter: ANDROID_XML },
|
|
586
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "@style/ usage", regex: /@style\//, fileFilter: ANDROID_XML },
|
|
587
|
+
// Layout
|
|
588
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "dp units", regex: /\d+dp\b/, fileFilter: ANDROID_XML },
|
|
589
|
+
{ category: "foundations", subcategory: "layout", type: "concern", pattern: "px units in XML", regex: /\d+px\b/, fileFilter: ANDROID_XML },
|
|
590
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "@dimen/ resource", regex: /@dimen\//, fileFilter: ANDROID_XML },
|
|
591
|
+
// Components
|
|
592
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "ConstraintLayout", regex: /ConstraintLayout/, fileFilter: ANDROID_XML },
|
|
593
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "RecyclerView", regex: /RecyclerView/, fileFilter: ANDROID_XML },
|
|
594
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "BottomNavigationView", regex: /BottomNavigationView/, fileFilter: ANDROID_XML },
|
|
595
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NavigationView", regex: /NavigationView/, fileFilter: ANDROID_XML },
|
|
596
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "MaterialButton", regex: /MaterialButton/, fileFilter: ANDROID_XML },
|
|
597
|
+
// Touch targets
|
|
598
|
+
{ category: "foundations", subcategory: "touchTargets", type: "positive", pattern: "minHeight 48dp", regex: /android:minHeight=["']4[4-8]dp/, fileFilter: ANDROID_XML },
|
|
599
|
+
];
|
|
600
|
+
|
|
601
|
+
// ════════════════════════════════════════════════════════════════
|
|
602
|
+
// REACT NATIVE RULES (~15 rules)
|
|
603
|
+
// ════════════════════════════════════════════════════════════════
|
|
604
|
+
const reactNativeRules: PatternRule[] = [
|
|
605
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityLabel", regex: /accessibilityLabel=/, fileFilter: TSX_JSX },
|
|
606
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityRole", regex: /accessibilityRole=/, fileFilter: TSX_JSX },
|
|
607
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityHint", regex: /accessibilityHint=/, fileFilter: TSX_JSX },
|
|
608
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessibilityState", regex: /accessibilityState=/, fileFilter: TSX_JSX },
|
|
609
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "accessible={true}", regex: /accessible=\{true\}/, fileFilter: TSX_JSX },
|
|
610
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "useColorScheme", regex: /useColorScheme\b/, fileFilter: TS_JS },
|
|
611
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "useWindowDimensions", regex: /useWindowDimensions\b/, fileFilter: TS_JS },
|
|
612
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "React Navigation", regex: /createNativeStackNavigator|createBottomTabNavigator|NavigationContainer/, fileFilter: TS_JS },
|
|
613
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "FlatList", regex: /\bFlatList\b/, fileFilter: TSX_JSX },
|
|
614
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "SectionList", regex: /\bSectionList\b/, fileFilter: TSX_JSX },
|
|
615
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "SafeAreaView", regex: /\bSafeAreaView\b/, fileFilter: TSX_JSX },
|
|
616
|
+
{ category: "inputs", subcategory: "gestures", type: "pattern", pattern: "Gesture handler", regex: /PanGestureHandler|TapGestureHandler|GestureDetector/, fileFilter: TSX_JSX },
|
|
617
|
+
{ category: "patterns", subcategory: "haptics", type: "pattern", pattern: "Haptics", regex: /Haptics\.|expo-haptics/, fileFilter: TS_JS },
|
|
618
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "nested touchables", regex: /accessible=\{true\}[\s\S]*?<Touchable/, fileFilter: TSX_JSX },
|
|
619
|
+
];
|
|
620
|
+
|
|
621
|
+
// ════════════════════════════════════════════════════════════════
|
|
622
|
+
// FLUTTER RULES (~20 rules)
|
|
623
|
+
// ════════════════════════════════════════════════════════════════
|
|
624
|
+
const flutterRules: PatternRule[] = [
|
|
625
|
+
// Accessibility
|
|
626
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "Semantics widget", regex: /\bSemantics\(/, fileFilter: DART },
|
|
627
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "ExcludeSemantics", regex: /\bExcludeSemantics\(/, fileFilter: DART },
|
|
628
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "MergeSemantics", regex: /\bMergeSemantics\(/, fileFilter: DART },
|
|
629
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "semanticLabel", regex: /semanticLabel:/, fileFilter: DART },
|
|
630
|
+
// Color
|
|
631
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "Theme color", regex: /Theme\.of\(context\)\.colorScheme/, fileFilter: DART },
|
|
632
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color", regex: /Color\(0x[0-9a-fA-F]+\)/, fileFilter: DART },
|
|
633
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "Colors.red/blue", regex: /Colors\.(red|blue|green|yellow|orange|purple|pink|white|black|grey)\b/, fileFilter: DART },
|
|
634
|
+
// Typography
|
|
635
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "Theme text style", regex: /Theme\.of\(context\)\.textTheme/, fileFilter: DART },
|
|
636
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded fontSize", regex: /fontSize:\s*\d+/, fileFilter: DART },
|
|
637
|
+
// Dark mode
|
|
638
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "brightness detection", regex: /MediaQuery\.of\(context\)\.platformBrightness/, fileFilter: DART },
|
|
639
|
+
{ category: "foundations", subcategory: "darkMode", type: "positive", pattern: "darkTheme", regex: /darkTheme:/, fileFilter: DART },
|
|
640
|
+
// Layout
|
|
641
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "MediaQuery responsive", regex: /MediaQuery\.of\(context\)\.size/, fileFilter: DART },
|
|
642
|
+
{ category: "foundations", subcategory: "layout", type: "positive", pattern: "LayoutBuilder", regex: /\bLayoutBuilder\b/, fileFilter: DART },
|
|
643
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "Navigator", regex: /\bNavigator\b/, fileFilter: DART },
|
|
644
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "CupertinoTabBar", regex: /\bCupertinoTabBar\b/, fileFilter: DART },
|
|
645
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "GoRouter", regex: /\bGoRouter\b/, fileFilter: DART },
|
|
646
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "ListView", regex: /\bListView\b/, fileFilter: DART },
|
|
647
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "GridView", regex: /\bGridView\b/, fileFilter: DART },
|
|
648
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "CupertinoButton", regex: /\bCupertinoButton\b/, fileFilter: DART },
|
|
649
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "ElevatedButton", regex: /\bElevatedButton\b/, fileFilter: DART },
|
|
650
|
+
// i18n
|
|
651
|
+
{ category: "patterns", subcategory: "i18n", type: "positive", pattern: "Flutter l10n", regex: /AppLocalizations|flutter_localizations|intl/, fileFilter: DART },
|
|
652
|
+
];
|
|
653
|
+
|
|
654
|
+
// ════════════════════════════════════════════════════════════════
|
|
655
|
+
// UIKIT RULES (iOS/iPadOS, Swift)
|
|
656
|
+
// ════════════════════════════════════════════════════════════════
|
|
657
|
+
// Distinct from the SwiftUI rules above: these match UIKit-specific APIs, so a
|
|
658
|
+
// pure-SwiftUI file won't trigger them and vice versa. Hardcoded UIColor(red:)
|
|
659
|
+
// and UIFont.systemFont(ofSize:) are already covered by the swift section and
|
|
660
|
+
// deliberately not repeated here to avoid double-counting.
|
|
661
|
+
const uikitRules: PatternRule[] = [
|
|
662
|
+
// Navigation & structure
|
|
663
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "UINavigationController", regex: /\bUINavigationController\b/, fileFilter: SWIFT },
|
|
664
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "UITabBarController", regex: /\bUITabBarController\b/, fileFilter: SWIFT },
|
|
665
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "UISplitViewController", regex: /\bUISplitViewController\b/, fileFilter: SWIFT },
|
|
666
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "UIPageViewController", regex: /\bUIPageViewController\b/, fileFilter: SWIFT },
|
|
667
|
+
{ category: "components-layout", subcategory: "lists", type: "pattern", pattern: "UICollectionView", regex: /\bUICollectionView\b/, fileFilter: SWIFT },
|
|
668
|
+
{ category: "components-layout", subcategory: "lists", type: "pattern", pattern: "UITableView", regex: /\bUITableView\b/, fileFilter: SWIFT },
|
|
669
|
+
{ category: "components-layout", subcategory: "layout", type: "pattern", pattern: "UIStackView", regex: /\bUIStackView\b/, fileFilter: SWIFT },
|
|
670
|
+
{ category: "components-search", subcategory: "search", type: "pattern", pattern: "UISearchController", regex: /\bUISearchController\b/, fileFilter: SWIFT },
|
|
671
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "UIMenu", regex: /\bUIMenu\b/, fileFilter: SWIFT },
|
|
672
|
+
{ category: "components-menus", subcategory: "menus", type: "pattern", pattern: "UIContextMenuConfiguration", regex: /\bUIContextMenuConfiguration\b/, fileFilter: SWIFT },
|
|
673
|
+
{ category: "components-status", subcategory: "modals", type: "pattern", pattern: "UIAlertController", regex: /\bUIAlertController\b/, fileFilter: SWIFT },
|
|
674
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "UISegmentedControl", regex: /\bUISegmentedControl\b/, fileFilter: SWIFT },
|
|
675
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "UISwitch", regex: /\bUISwitch\b/, fileFilter: SWIFT },
|
|
676
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "UIStepper", regex: /\bUIStepper\b/, fileFilter: SWIFT },
|
|
677
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "UIToolbar", regex: /\bUIToolbar\b/, fileFilter: SWIFT },
|
|
678
|
+
|
|
679
|
+
// Typography — Dynamic Type
|
|
680
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "UIKit preferredFont", regex: /preferredFont\(forTextStyle:/, fileFilter: SWIFT },
|
|
681
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "adjustsFontForContentSizeCategory", regex: /adjustsFontForContentSizeCategory\s*=\s*true/, fileFilter: SWIFT },
|
|
682
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded UIFont(name:)", regex: /UIFont\(name:[^)]*,\s*size:\s*\d/, fileFilter: SWIFT },
|
|
683
|
+
|
|
684
|
+
// Color — semantic vs hardcoded
|
|
685
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "UIKit semantic color", regex: /UIColor\.(label|secondaryLabel|tertiaryLabel|systemBackground|secondarySystemBackground|tintColor|systemFill|separator|link)\b/, fileFilter: SWIFT },
|
|
686
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded UIColor constant", regex: /UIColor\.(white|black|gray|lightGray|darkGray|red|blue|green|yellow|orange|purple|brown|cyan|magenta)\b/, fileFilter: SWIFT },
|
|
687
|
+
|
|
688
|
+
// Accessibility
|
|
689
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "UIKit accessibilityLabel", regex: /\.accessibilityLabel\s*=/, fileFilter: SWIFT },
|
|
690
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "UIKit isAccessibilityElement", regex: /\.isAccessibilityElement\s*=\s*true/, fileFilter: SWIFT },
|
|
691
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "UIKit accessibilityTraits", regex: /\.accessibilityTraits\s*=/, fileFilter: SWIFT },
|
|
692
|
+
{ category: "foundations", subcategory: "accessibility", type: "concern", pattern: "viewWithTag lookup", regex: /\.viewWithTag\(/, fileFilter: SWIFT },
|
|
693
|
+
|
|
694
|
+
// SF Symbols
|
|
695
|
+
{ category: "foundations", subcategory: "sf-symbols", type: "positive", pattern: "UIImage(systemName:)", regex: /UIImage\(systemName:/, fileFilter: SWIFT },
|
|
696
|
+
|
|
697
|
+
// Layout — Auto Layout & safe area
|
|
698
|
+
{ category: "components-layout", subcategory: "layout", type: "positive", pattern: "Auto Layout constraints", regex: /NSLayoutConstraint|\.constraint\(equalTo:/, fileFilter: SWIFT },
|
|
699
|
+
{ category: "components-layout", subcategory: "layout", type: "positive", pattern: "safeAreaLayoutGuide", regex: /safeAreaLayoutGuide/, fileFilter: SWIFT },
|
|
700
|
+
{ category: "components-layout", subcategory: "layout", type: "concern", pattern: "UIScreen.main.bounds for layout", regex: /UIScreen\.main\.bounds/, fileFilter: SWIFT },
|
|
701
|
+
|
|
702
|
+
// Haptics
|
|
703
|
+
{ category: "patterns", subcategory: "haptics", type: "positive", pattern: "UIFeedbackGenerator", regex: /UI(Impact|Notification|Selection)FeedbackGenerator/, fileFilter: SWIFT },
|
|
704
|
+
|
|
705
|
+
// Dark mode
|
|
706
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "userInterfaceStyle", regex: /traitCollection\.userInterfaceStyle|overrideUserInterfaceStyle/, fileFilter: SWIFT },
|
|
707
|
+
|
|
708
|
+
// Deprecated APIs
|
|
709
|
+
{ category: "components-status", subcategory: "modals", type: "concern", pattern: "UIAlertView (deprecated)", regex: /\bUIAlertView\b/, fileFilter: SWIFT },
|
|
710
|
+
{ category: "components-status", subcategory: "modals", type: "concern", pattern: "UIActionSheet (deprecated)", regex: /\bUIActionSheet\b/, fileFilter: SWIFT },
|
|
711
|
+
{ category: "technologies", subcategory: "structure", type: "concern", pattern: "UIWebView (deprecated)", regex: /\bUIWebView\b/, fileFilter: SWIFT },
|
|
712
|
+
{ category: "components-search", subcategory: "search", type: "concern", pattern: "UISearchDisplayController (deprecated)", regex: /\bUISearchDisplayController\b/, fileFilter: SWIFT },
|
|
713
|
+
{ category: "foundations", subcategory: "structure", type: "concern", pattern: "setStatusBarStyle (deprecated)", regex: /setStatusBarStyle|statusBarStyle\s*=/, fileFilter: SWIFT },
|
|
714
|
+
];
|
|
715
|
+
|
|
716
|
+
// ════════════════════════════════════════════════════════════════
|
|
717
|
+
// APPKIT RULES (macOS, Swift)
|
|
718
|
+
// ════════════════════════════════════════════════════════════════
|
|
719
|
+
const appkitRules: PatternRule[] = [
|
|
720
|
+
// Structure
|
|
721
|
+
{ category: "components-layout", subcategory: "windows", type: "pattern", pattern: "NSWindow", regex: /\bNSWindow\b/, fileFilter: SWIFT },
|
|
722
|
+
{ category: "components-layout", subcategory: "windows", type: "pattern", pattern: "NSWindowController", regex: /\bNSWindowController\b/, fileFilter: SWIFT },
|
|
723
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "NSSplitViewController", regex: /\bNSSplitViewController\b/, fileFilter: SWIFT },
|
|
724
|
+
{ category: "components-layout", subcategory: "sidebars", type: "pattern", pattern: "NSOutlineView", regex: /\bNSOutlineView\b/, fileFilter: SWIFT },
|
|
725
|
+
{ category: "components-layout", subcategory: "lists", type: "pattern", pattern: "NSTableView", regex: /\bNSTableView\b/, fileFilter: SWIFT },
|
|
726
|
+
{ category: "components-layout", subcategory: "lists", type: "pattern", pattern: "NSCollectionView", regex: /\bNSCollectionView\b/, fileFilter: SWIFT },
|
|
727
|
+
{ category: "components-layout", subcategory: "toolbar", type: "pattern", pattern: "NSToolbar", regex: /\bNSToolbar\b/, fileFilter: SWIFT },
|
|
728
|
+
{ category: "components-menus", subcategory: "menu-bar", type: "pattern", pattern: "NSMenu", regex: /\bNSMenu\b/, fileFilter: SWIFT },
|
|
729
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "NSButton", regex: /\bNSButton\b/, fileFilter: SWIFT },
|
|
730
|
+
{ category: "components-controls", subcategory: "controls", type: "pattern", pattern: "NSSegmentedControl", regex: /\bNSSegmentedControl\b/, fileFilter: SWIFT },
|
|
731
|
+
{ category: "components-status", subcategory: "modals", type: "pattern", pattern: "NSAlert", regex: /\bNSAlert\b/, fileFilter: SWIFT },
|
|
732
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "NSComboBox", regex: /\bNSComboBox\b/, fileFilter: SWIFT },
|
|
733
|
+
{ category: "components-controls", subcategory: "inputs", type: "pattern", pattern: "NSPopUpButton", regex: /\bNSPopUpButton\b/, fileFilter: SWIFT },
|
|
734
|
+
|
|
735
|
+
// Materials & vibrancy (macOS)
|
|
736
|
+
{ category: "foundations", subcategory: "materials", type: "pattern", pattern: "NSVisualEffectView", regex: /\bNSVisualEffectView\b/, fileFilter: SWIFT },
|
|
737
|
+
{ category: "foundations", subcategory: "materials", type: "positive", pattern: "NSVisualEffect material", regex: /\.material\s*=\s*\.(sidebar|menu|popover|headerView|contentBackground|windowBackground|hudWindow|underWindowBackground)/, fileFilter: SWIFT },
|
|
738
|
+
|
|
739
|
+
// Color — semantic vs hardcoded
|
|
740
|
+
{ category: "foundations", subcategory: "color", type: "positive", pattern: "NSColor semantic", regex: /NSColor\.(labelColor|secondaryLabelColor|controlAccentColor|windowBackgroundColor|textColor|controlColor|separatorColor|linkColor)\b/, fileFilter: SWIFT },
|
|
741
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded NSColor(red:)", regex: /NSColor\(\s*(calibratedRed|deviceRed|red):/, fileFilter: SWIFT },
|
|
742
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded NSColor constant", regex: /NSColor\.(white|black|gray|red|blue|green|yellow|orange|purple)\b/, fileFilter: SWIFT },
|
|
743
|
+
|
|
744
|
+
// Typography
|
|
745
|
+
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "NSFont.preferredFont", regex: /NSFont\.preferredFont\(forTextStyle:/, fileFilter: SWIFT },
|
|
746
|
+
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded NSFont size", regex: /NSFont\.systemFont\(ofSize:\s*\d/, fileFilter: SWIFT },
|
|
747
|
+
|
|
748
|
+
// Accessibility
|
|
749
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "setAccessibilityLabel", regex: /setAccessibilityLabel\(|\.accessibilityLabel\s*=/, fileFilter: SWIFT },
|
|
750
|
+
{ category: "foundations", subcategory: "accessibility", type: "positive", pattern: "NSAccessibility protocol", regex: /NSAccessibilityElement|isAccessibilityElement\(\)/, fileFilter: SWIFT },
|
|
751
|
+
|
|
752
|
+
// Layout
|
|
753
|
+
{ category: "components-layout", subcategory: "layout", type: "positive", pattern: "AppKit Auto Layout", regex: /translatesAutoresizingMaskIntoConstraints\s*=\s*false/, fileFilter: SWIFT },
|
|
754
|
+
|
|
755
|
+
// Pointer
|
|
756
|
+
{ category: "inputs", subcategory: "keyboard", type: "positive", pattern: "NSCursor", regex: /\bNSCursor\b/, fileFilter: SWIFT },
|
|
757
|
+
|
|
758
|
+
// Deprecated
|
|
759
|
+
{ category: "components-menus", subcategory: "menu-bar", type: "concern", pattern: "NSMenuItem setSubmenu (deprecated)", regex: /setSubmenu:forItem:/, fileFilter: SWIFT },
|
|
760
|
+
];
|
|
761
|
+
|
|
762
|
+
// ════════════════════════════════════════════════════════════════
|
|
763
|
+
// WATCHOS RULES (Swift / SwiftUI + WatchKit)
|
|
764
|
+
// ════════════════════════════════════════════════════════════════
|
|
765
|
+
const watchosRules: PatternRule[] = [
|
|
766
|
+
// WatchKit structure
|
|
767
|
+
{ category: "components-layout", subcategory: "navigation", type: "pattern", pattern: "WKInterfaceController", regex: /\bWKInterfaceController\b/, fileFilter: SWIFT },
|
|
768
|
+
{ category: "platforms", subcategory: "navigation", type: "pattern", pattern: "WKHostingController", regex: /\bWKHostingController\b/, fileFilter: SWIFT },
|
|
769
|
+
|
|
770
|
+
// Digital Crown
|
|
771
|
+
{ category: "inputs", subcategory: "digital-crown", type: "positive", pattern: "digitalCrownRotation", regex: /\.digitalCrownRotation\(/, fileFilter: SWIFT },
|
|
772
|
+
{ category: "inputs", subcategory: "digital-crown", type: "pattern", pattern: "WKCrownSequencer", regex: /\bWKCrownSequencer\b|crownSequencer/, fileFilter: SWIFT },
|
|
773
|
+
{ category: "inputs", subcategory: "digital-crown", type: "positive", pattern: "focusable for crown", regex: /\.focusable\(/, fileFilter: SWIFT },
|
|
774
|
+
|
|
775
|
+
// Complications
|
|
776
|
+
{ category: "platforms", subcategory: "complications", type: "pattern", pattern: "CLKComplication", regex: /\bCLKComplication/, fileFilter: SWIFT },
|
|
777
|
+
{ category: "platforms", subcategory: "complications", type: "pattern", pattern: "WidgetKit complication", regex: /CLKComplicationWidgetMigrator|\.accessoryCircular|\.accessoryCorner/, fileFilter: SWIFT },
|
|
778
|
+
|
|
779
|
+
// Always-On / luminance
|
|
780
|
+
{ category: "platforms", subcategory: "always-on", type: "positive", pattern: "isLuminanceReduced", regex: /isLuminanceReduced/, fileFilter: SWIFT },
|
|
781
|
+
{ category: "platforms", subcategory: "always-on", type: "positive", pattern: "privacySensitive", regex: /\.privacySensitive\(/, fileFilter: SWIFT },
|
|
782
|
+
|
|
783
|
+
// Watch faces / workouts
|
|
784
|
+
{ category: "platforms", subcategory: "workouts", type: "pattern", pattern: "HKWorkoutSession", regex: /\bHKWorkoutSession\b/, fileFilter: SWIFT },
|
|
785
|
+
{ category: "platforms", subcategory: "workouts", type: "positive", pattern: "WKExtendedRuntimeSession", regex: /\bWKExtendedRuntimeSession\b/, fileFilter: SWIFT },
|
|
786
|
+
|
|
787
|
+
// Haptics (watch)
|
|
788
|
+
{ category: "patterns", subcategory: "haptics", type: "positive", pattern: "WKInterfaceDevice haptic", regex: /WKInterfaceDevice\.current\(\)\.play\(/, fileFilter: SWIFT },
|
|
789
|
+
|
|
790
|
+
// Notifications
|
|
791
|
+
{ category: "patterns", subcategory: "state", type: "pattern", pattern: "WKUserNotificationInterfaceController", regex: /\bWKUserNotificationInterfaceController\b/, fileFilter: SWIFT },
|
|
792
|
+
];
|
|
793
|
+
|
|
794
|
+
// ════════════════════════════════════════════════════════════════
|
|
795
|
+
// VISIONOS RULES (Swift / SwiftUI + RealityKit)
|
|
796
|
+
// ════════════════════════════════════════════════════════════════
|
|
797
|
+
const visionosRules: PatternRule[] = [
|
|
798
|
+
// Windows, volumes, immersive spaces
|
|
799
|
+
{ category: "components-layout", subcategory: "windows", type: "pattern", pattern: "visionOS volumetric window", regex: /\.windowStyle\(\.volumetric\)/, fileFilter: SWIFT },
|
|
800
|
+
{ category: "platforms", subcategory: "immersive", type: "pattern", pattern: "ImmersiveSpace", regex: /\bImmersiveSpace\b/, fileFilter: SWIFT },
|
|
801
|
+
{ category: "platforms", subcategory: "immersive", type: "positive", pattern: "immersionStyle mixed", regex: /\.immersionStyle\(/, fileFilter: SWIFT },
|
|
802
|
+
{ category: "platforms", subcategory: "spatial", type: "pattern", pattern: "RealityView", regex: /\bRealityView\b/, fileFilter: SWIFT },
|
|
803
|
+
|
|
804
|
+
// Ornaments
|
|
805
|
+
{ category: "components-layout", subcategory: "ornaments", type: "positive", pattern: "ornament", regex: /\.ornament\(/, fileFilter: SWIFT },
|
|
806
|
+
|
|
807
|
+
// Glass materials
|
|
808
|
+
{ category: "foundations", subcategory: "materials", type: "positive", pattern: "glassBackgroundEffect", regex: /\.glassBackgroundEffect\(/, fileFilter: SWIFT },
|
|
809
|
+
|
|
810
|
+
// Hover / gaze interaction
|
|
811
|
+
{ category: "inputs", subcategory: "spatial", type: "positive", pattern: "hoverEffect", regex: /\.hoverEffect\(/, fileFilter: SWIFT },
|
|
812
|
+
{ category: "inputs", subcategory: "spatial", type: "positive", pattern: "visionOS spatial gesture", regex: /SpatialTapGesture|\.targetedToAnyEntity\(/, fileFilter: SWIFT },
|
|
813
|
+
|
|
814
|
+
// Depth / 3D layout
|
|
815
|
+
{ category: "components-layout", subcategory: "spatial", type: "pattern", pattern: "Model3D", regex: /\bModel3D\b/, fileFilter: SWIFT },
|
|
816
|
+
{ category: "components-layout", subcategory: "spatial", type: "positive", pattern: "depth alignment", regex: /\.offset\(z:|alignment3D/, fileFilter: SWIFT },
|
|
817
|
+
];
|
|
818
|
+
|
|
819
|
+
// ════════════════════════════════════════════════════════════════
|
|
820
|
+
// RULE CATALOG
|
|
821
|
+
// ════════════════════════════════════════════════════════════════
|
|
822
|
+
// Every rule gets a stable ID: <framework>/<slug-of-pattern-label>. IDs are
|
|
823
|
+
// public API — suppressions, baselines, and SARIF all key on them — so pattern
|
|
824
|
+
// labels are frozen once released. Renaming a label is a breaking change.
|
|
825
|
+
|
|
826
|
+
export interface CatalogRule extends PatternRule {
|
|
827
|
+
id: string;
|
|
828
|
+
framework: string;
|
|
829
|
+
engine: Engine;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function slugify(label: string): string {
|
|
833
|
+
return label
|
|
834
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
835
|
+
.toLowerCase()
|
|
836
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
837
|
+
.replace(/^-+|-+$/g, "");
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
const SECTIONS: Array<[framework: string, rules: PatternRule[]]> = [
|
|
841
|
+
["swift", swiftRules],
|
|
842
|
+
["uikit", uikitRules],
|
|
843
|
+
["appkit", appkitRules],
|
|
844
|
+
["watchos", watchosRules],
|
|
845
|
+
["visionos", visionosRules],
|
|
846
|
+
["web", webCodeRules],
|
|
847
|
+
["css", cssRules],
|
|
848
|
+
["vue", vueRules],
|
|
849
|
+
["svelte", svelteRules],
|
|
850
|
+
["angular", angularRules],
|
|
851
|
+
["compose", kotlinRules],
|
|
852
|
+
["android-xml", androidXmlRules],
|
|
853
|
+
["react-native", reactNativeRules],
|
|
854
|
+
["flutter", flutterRules],
|
|
855
|
+
];
|
|
856
|
+
|
|
857
|
+
const allRules: CatalogRule[] = [];
|
|
858
|
+
// Rules whose findings a refinement engine adjudicates. The declared engine is
|
|
859
|
+
// the strongest tier that runs for the rule; the regex definition remains as
|
|
860
|
+
// the fallback when a tier is unavailable (e.g. ast-tsx without typescript).
|
|
861
|
+
// analyze.ts and the engine modules must own the same IDs.
|
|
862
|
+
const ENGINE_BY_RULE_ID: Record<string, Engine> = {
|
|
863
|
+
"swift/image-without-a11y": "swift-structural",
|
|
864
|
+
"swift/on-tap-gesture-without-traits": "swift-structural",
|
|
865
|
+
"web/missing-alt": "ast-tsx",
|
|
866
|
+
"web/image-without-alt": "ast-tsx",
|
|
867
|
+
"web/div-with-on-click-no-role": "ast-tsx",
|
|
868
|
+
"web/span-with-on-click-no-role": "ast-tsx",
|
|
869
|
+
"web/positive-tabindex": "ast-tsx",
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
{
|
|
873
|
+
const used = new Set<string>();
|
|
874
|
+
for (const [framework, rules] of SECTIONS) {
|
|
875
|
+
for (const rule of rules) {
|
|
876
|
+
const base = `${framework}/${slugify(rule.pattern)}`;
|
|
877
|
+
// Duplicate labels within a framework get a stable ordinal suffix; the
|
|
878
|
+
// suffix only ever grows with rule additions at the end of a section.
|
|
879
|
+
let id = base;
|
|
880
|
+
for (let n = 2; used.has(id); n++) id = `${base}-${n}`;
|
|
881
|
+
used.add(id);
|
|
882
|
+
allRules.push({ ...rule, id, framework, engine: ENGINE_BY_RULE_ID[id] ?? "regex" });
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// Best-fit HIG citation per rule subcategory. Values are HIG topic slugs that
|
|
888
|
+
// must exist in skills/*/references/ (enforced by patterns.test.ts); "" cites
|
|
889
|
+
// the HIG root for subcategories with no single canonical page.
|
|
890
|
+
const HIG_BASE = "https://developer.apple.com/design/human-interface-guidelines/";
|
|
891
|
+
const SUBCATEGORY_HIG: Record<string, string> = {
|
|
892
|
+
accessibility: "accessibility",
|
|
893
|
+
accordion: "disclosure-controls",
|
|
894
|
+
alerts: "alerts",
|
|
895
|
+
analytics: "privacy",
|
|
896
|
+
animation: "motion",
|
|
897
|
+
buttons: "buttons",
|
|
898
|
+
cards: "layout",
|
|
899
|
+
color: "color",
|
|
900
|
+
controls: "controls",
|
|
901
|
+
details: "disclosure-controls",
|
|
902
|
+
focus: "focus-and-selection",
|
|
903
|
+
forms: "entering-data",
|
|
904
|
+
gestures: "gestures",
|
|
905
|
+
haptics: "playing-haptics",
|
|
906
|
+
images: "images",
|
|
907
|
+
inputs: "text-fields",
|
|
908
|
+
keyboard: "keyboards",
|
|
909
|
+
layout: "layout",
|
|
910
|
+
lists: "lists-and-tables",
|
|
911
|
+
loading: "loading",
|
|
912
|
+
menus: "menus",
|
|
913
|
+
modals: "modality",
|
|
914
|
+
motion: "motion",
|
|
915
|
+
multiplatform: "",
|
|
916
|
+
navigation: "",
|
|
917
|
+
popover: "popovers",
|
|
918
|
+
progress: "progress-indicators",
|
|
919
|
+
refresh: "loading",
|
|
920
|
+
search: "searching",
|
|
921
|
+
seo: "",
|
|
922
|
+
state: "feedback",
|
|
923
|
+
structure: "layout",
|
|
924
|
+
tables: "lists-and-tables",
|
|
925
|
+
toast: "feedback",
|
|
926
|
+
toggle: "toggles",
|
|
927
|
+
toolbar: "toolbars",
|
|
928
|
+
tooltip: "offering-help",
|
|
929
|
+
typography: "typography",
|
|
930
|
+
widgets: "widgets",
|
|
931
|
+
// Apple-platform subcategories
|
|
932
|
+
windows: "windows",
|
|
933
|
+
sidebars: "sidebars",
|
|
934
|
+
"split-views": "split-views",
|
|
935
|
+
"menu-bar": "the-menu-bar",
|
|
936
|
+
materials: "materials",
|
|
937
|
+
"sf-symbols": "sf-symbols",
|
|
938
|
+
"digital-crown": "digital-crown",
|
|
939
|
+
complications: "complications",
|
|
940
|
+
"always-on": "always-on",
|
|
941
|
+
workouts: "workouts",
|
|
942
|
+
immersive: "immersive-experiences",
|
|
943
|
+
spatial: "spatial-layout",
|
|
944
|
+
ornaments: "ornaments",
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
export function higCitation(rule: Pick<CatalogRule, "hig" | "subcategory">): string {
|
|
948
|
+
if (rule.hig) return rule.hig;
|
|
949
|
+
const slug = SUBCATEGORY_HIG[rule.subcategory] ?? "";
|
|
950
|
+
return HIG_BASE + slug;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// Fix guidance keyed by pattern label. Covers every critical and serious
|
|
954
|
+
// concern plus the most common moderates; docs generation surfaces gaps.
|
|
955
|
+
const FIX_GUIDANCE: Record<string, string> = {
|
|
956
|
+
// Critical
|
|
957
|
+
"missing alt": "Add descriptive alt text, or alt=\"\" when the image is purely decorative.",
|
|
958
|
+
"Image without alt": "Add descriptive alt text, or alt=\"\" when the image is purely decorative.",
|
|
959
|
+
"svg without a11y": "Give inline SVG role=\"img\" plus a <title> or aria-label, or aria-hidden=\"true\" if decorative.",
|
|
960
|
+
"empty heading": "Add text content to the heading or remove it; screen readers announce empty headings as unlabeled.",
|
|
961
|
+
"empty button": "Give the button visible text or an aria-label.",
|
|
962
|
+
"missing html lang": "Add lang=\"…\" to the <html> element so assistive tech picks the right voice.",
|
|
963
|
+
"video without track": "Add a <track kind=\"captions\"> file to the video.",
|
|
964
|
+
"blink element": "Remove <blink>; if emphasis is needed, use CSS animation that honors prefers-reduced-motion.",
|
|
965
|
+
"marquee element": "Remove <marquee>; use static layout or an accessible animation that honors prefers-reduced-motion.",
|
|
966
|
+
"user-scalable=no": "Remove user-scalable=no from the viewport meta so pinch-zoom keeps working.",
|
|
967
|
+
"maximum-scale=1": "Remove maximum-scale=1 from the viewport meta so users can zoom.",
|
|
968
|
+
"ImageView without contentDescription": "Add android:contentDescription, or importantForAccessibility=\"no\" if decorative.",
|
|
969
|
+
// Serious
|
|
970
|
+
"isAccessibilityElement false on interactive": "Keep interactive elements exposed to accessibility; give them a label instead of hiding them.",
|
|
971
|
+
"div with onClick no role": "Use a native <button>, or add role=\"button\", tabIndex={0}, and Enter/Space key handling.",
|
|
972
|
+
"span with onClick no role": "Use a native <button>, or add role=\"button\", tabIndex={0}, and Enter/Space key handling.",
|
|
973
|
+
"ambiguous link text": "Write link text that names the destination; avoid \"click here\"/\"read more\".",
|
|
974
|
+
"positive tabindex": "Use tabindex=\"0\" (or -1); positive values override the natural focus order.",
|
|
975
|
+
"aria-hidden on focusable": "Remove aria-hidden from focusable elements, or take them out of the tab order too.",
|
|
976
|
+
"onMouseOver without onFocus": "Pair onMouseOver with onFocus so keyboard users get the same affordance.",
|
|
977
|
+
"onMouseOut without onBlur": "Pair onMouseOut with onBlur so keyboard users get the same affordance.",
|
|
978
|
+
"div as button": "Replace the div with a native <button>; it brings focus, key handling, and semantics for free.",
|
|
979
|
+
"div as nav/header class": "Use the semantic <nav>/<header> element instead of a classed div so landmarks exist.",
|
|
980
|
+
"autoplay media": "Avoid autoplay; if unavoidable, autoplay muted with visible controls.",
|
|
981
|
+
"outline none": "Keep a visible focus indicator — style :focus-visible instead of removing the outline.",
|
|
982
|
+
"v-on:click without keyboard": "Add @keydown.enter/@keydown.space handling, or use a <button>.",
|
|
983
|
+
"on:click without on:keydown": "Add on:keydown handling, or use a <button>.",
|
|
984
|
+
"(click) without (keydown)": "Add a (keydown) handler, or use a <button>.",
|
|
985
|
+
"clickable without Role": "Pass role = Role.Button (or use Modifier.semantics) so TalkBack announces the control.",
|
|
986
|
+
"nested touchables": "Flatten nested touchables; keep one interactive wrapper per control.",
|
|
987
|
+
// Common moderates
|
|
988
|
+
"hardcodedColor": "Use semantic colors (.primary, .secondary, or an asset-catalog color) that adapt to dark mode.",
|
|
989
|
+
"hardcodedRGBColor": "Move the color into an asset catalog with light/dark variants.",
|
|
990
|
+
"hardcodedUIColor": "Use a semantic UIColor (label, systemBackground) or an asset-catalog color.",
|
|
991
|
+
"NavigationView (deprecated)": "Migrate to NavigationStack (single column) or NavigationSplitView (sidebar layouts).",
|
|
992
|
+
"onTapGesture without traits": "Prefer Button, or add .accessibilityAddTraits(.isButton) so VoiceOver announces it.",
|
|
993
|
+
// UIKit
|
|
994
|
+
"hardcoded UIColor constant": "Use a semantic UIColor (.label, .systemBackground, .tintColor) that adapts to appearance.",
|
|
995
|
+
"hardcoded UIFont(name:)": "Scale custom fonts with UIFontMetrics, or use preferredFont(forTextStyle:).",
|
|
996
|
+
"viewWithTag lookup": "Reference views by outlet or property; tag-based lookup is fragile and breaks with view reordering.",
|
|
997
|
+
"UIScreen.main.bounds for layout": "Lay out against the view's bounds or safeAreaLayoutGuide; UIScreen.main ignores Split View and Slide Over.",
|
|
998
|
+
"UIAlertView (deprecated)": "Use UIAlertController with a .alert style.",
|
|
999
|
+
"UIActionSheet (deprecated)": "Use UIAlertController with an .actionSheet style.",
|
|
1000
|
+
"UIWebView (deprecated)": "Use WKWebView.",
|
|
1001
|
+
"UISearchDisplayController (deprecated)": "Use UISearchController.",
|
|
1002
|
+
"setStatusBarStyle (deprecated)": "Override preferredStatusBarStyle on the view controller instead.",
|
|
1003
|
+
// AppKit
|
|
1004
|
+
"hardcoded NSColor(red:)": "Use a semantic NSColor (.labelColor, .controlAccentColor) or a Color Set asset with light/dark variants.",
|
|
1005
|
+
"hardcoded NSColor constant": "Use a semantic NSColor (.labelColor, .windowBackgroundColor) that adapts to appearance and accent color.",
|
|
1006
|
+
"hardcoded NSFont size": "Use NSFont.preferredFont(forTextStyle:) so text respects the user's size settings.",
|
|
1007
|
+
"NSMenuItem setSubmenu (deprecated)": "Set the item's submenu property directly.",
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
export function fixGuidance(rule: Pick<CatalogRule, "fix" | "pattern">): string | null {
|
|
1011
|
+
return rule.fix ?? FIX_GUIDANCE[rule.pattern] ?? null;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// Public, serializable view of a rule for docs, SARIF, and the MCP server.
|
|
1015
|
+
export interface RuleMeta {
|
|
1016
|
+
id: string;
|
|
1017
|
+
framework: string;
|
|
1018
|
+
category: string;
|
|
1019
|
+
subcategory: string;
|
|
1020
|
+
type: "pattern" | "positive" | "concern";
|
|
1021
|
+
label: string;
|
|
1022
|
+
severity: Severity | null;
|
|
1023
|
+
engine: Engine;
|
|
1024
|
+
hig: string;
|
|
1025
|
+
fix: string | null;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function toMeta(rule: CatalogRule): RuleMeta {
|
|
1029
|
+
return {
|
|
1030
|
+
id: rule.id,
|
|
1031
|
+
framework: rule.framework,
|
|
1032
|
+
category: rule.category,
|
|
1033
|
+
subcategory: rule.subcategory,
|
|
1034
|
+
type: rule.type,
|
|
1035
|
+
label: rule.pattern,
|
|
1036
|
+
severity: rule.type === "concern" ? severityFor(rule.pattern) : null,
|
|
1037
|
+
engine: rule.engine,
|
|
1038
|
+
hig: higCitation(rule),
|
|
1039
|
+
fix: fixGuidance(rule),
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export function ruleCatalog(): RuleMeta[] {
|
|
1044
|
+
return allRules.map(toMeta);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
export function getRuleById(id: string): RuleMeta | undefined {
|
|
1048
|
+
const rule = allRules.find(r => r.id === id);
|
|
1049
|
+
return rule ? toMeta(rule) : undefined;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
interface CommentState {
|
|
1053
|
+
inBlock: boolean; // inside a /* ... */ block (CSS/SCSS/JS/Swift/Kotlin/Dart)
|
|
1054
|
+
inHtml: boolean; // inside an <!-- ... --> comment (HTML/XML/Vue/Svelte)
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// Remove comment content from a single line so rules never fire on commented-out
|
|
1058
|
+
// code or prose (e.g. "// disable autoplay"). String and template literals are
|
|
1059
|
+
// PRESERVED — their contents are exactly what many rules match on (role="button",
|
|
1060
|
+
// class="header", href="https://..."). Block (/* */) and HTML (<!-- -->) comment
|
|
1061
|
+
// state carries across lines via `state`; line (//) comments and string state are
|
|
1062
|
+
// line-local. This is a pragmatic lexer, not a full parser: good enough to kill
|
|
1063
|
+
// the dominant false-positive class without AST machinery.
|
|
1064
|
+
function stripComments(line: string, state: CommentState, lineComments: boolean): string {
|
|
1065
|
+
let out = "";
|
|
1066
|
+
let str: string | null = null; // active string delimiter, or null
|
|
1067
|
+
const n = line.length;
|
|
1068
|
+
let i = 0;
|
|
1069
|
+
while (i < n) {
|
|
1070
|
+
const c = line[i];
|
|
1071
|
+
const c2 = i + 1 < n ? line[i + 1] : "";
|
|
1072
|
+
if (state.inBlock) {
|
|
1073
|
+
if (c === "*" && c2 === "/") { state.inBlock = false; i += 2; } else { i++; }
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
if (state.inHtml) {
|
|
1077
|
+
if (c === "-" && c2 === "-" && line[i + 2] === ">") { state.inHtml = false; i += 3; } else { i++; }
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
if (str !== null) {
|
|
1081
|
+
out += c;
|
|
1082
|
+
if (c === "\\" && i + 1 < n) { out += c2; i += 2; continue; }
|
|
1083
|
+
if (c === str) str = null;
|
|
1084
|
+
i++;
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
if (c === '"' || c === "'" || c === "`") { str = c; out += c; i++; continue; }
|
|
1088
|
+
if (c === "/" && c2 === "*") { state.inBlock = true; i += 2; continue; }
|
|
1089
|
+
if (lineComments && c === "/" && c2 === "/") break; // line comment → drop the rest of the line
|
|
1090
|
+
if (c === "<" && c2 === "!" && line[i + 2] === "-" && line[i + 3] === "-") { state.inHtml = true; i += 4; continue; }
|
|
1091
|
+
out += c;
|
|
1092
|
+
i++;
|
|
1093
|
+
}
|
|
1094
|
+
return out;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// Inline suppressions. They live inside comments in any language, so they're
|
|
1098
|
+
// parsed from RAW lines (the comment stripper would otherwise delete them):
|
|
1099
|
+
// // hig-disable-next-line swift/hardcoded-color -- brand splash screen
|
|
1100
|
+
// <!-- hig-disable-next-line web/missing-alt -->
|
|
1101
|
+
// // hig-disable-file css/important
|
|
1102
|
+
// With no rule IDs, everything is suppressed. IDs may be exact or prefix globs
|
|
1103
|
+
// ("swift/*"). Text after "--" is a human reason and is ignored.
|
|
1104
|
+
interface Suppression {
|
|
1105
|
+
kind: "next-line" | "file";
|
|
1106
|
+
ids: string[] | "all";
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function parseSuppression(line: string): Suppression | null {
|
|
1110
|
+
const m = line.match(/hig-disable-(next-line|file)\b(.*)$/);
|
|
1111
|
+
if (!m) return null;
|
|
1112
|
+
const ids: string[] = [];
|
|
1113
|
+
for (const token of (m[2] ?? "").trim().split(/\s+/)) {
|
|
1114
|
+
if (token === "" || token === "--") break;
|
|
1115
|
+
if (!/^[a-z0-9/*-]+$/.test(token) || !token.includes("/")) break;
|
|
1116
|
+
ids.push(token);
|
|
1117
|
+
}
|
|
1118
|
+
return { kind: m[1] as Suppression["kind"], ids: ids.length > 0 ? ids : "all" };
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function suppressionCovers(ids: string[] | "all", ruleId: string): boolean {
|
|
1122
|
+
if (ids === "all") return true;
|
|
1123
|
+
return ids.some(id =>
|
|
1124
|
+
id.endsWith("*") ? ruleId.startsWith(id.slice(0, -1)) : ruleId === id,
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// The base regex tier. Every match it produces is tagged engine "regex" even
|
|
1129
|
+
// for rules whose declared (max) engine is stronger — those findings are only
|
|
1130
|
+
// upgraded to "swift-structural"/"ast-tsx" when analyzeFile runs the refinement
|
|
1131
|
+
// tiers on top. Callers wanting the strongest available analysis use analyzeFile.
|
|
1132
|
+
export function detectPatterns(code: string, file: string): PatternMatch[] {
|
|
1133
|
+
const matches: PatternMatch[] = [];
|
|
1134
|
+
const rawLines = code.split("\n");
|
|
1135
|
+
|
|
1136
|
+
// Collect suppressions before any stripping. next-line targets are 1-based.
|
|
1137
|
+
let fileSuppression: string[] | "all" | null = null;
|
|
1138
|
+
const lineSuppressions = new Map<number, string[] | "all">();
|
|
1139
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
1140
|
+
if (!rawLines[i].includes("hig-disable-")) continue;
|
|
1141
|
+
const sup = parseSuppression(rawLines[i]);
|
|
1142
|
+
if (!sup) continue;
|
|
1143
|
+
if (sup.kind === "file") {
|
|
1144
|
+
fileSuppression = fileSuppression === "all" || sup.ids === "all"
|
|
1145
|
+
? "all"
|
|
1146
|
+
: [...(fileSuppression ?? []), ...sup.ids];
|
|
1147
|
+
} else {
|
|
1148
|
+
const existing = lineSuppressions.get(i + 2);
|
|
1149
|
+
lineSuppressions.set(
|
|
1150
|
+
i + 2,
|
|
1151
|
+
existing === "all" || sup.ids === "all" ? "all" : [...(existing ?? []), ...sup.ids],
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
const isSuppressed = (ruleId: string, line: number): boolean => {
|
|
1156
|
+
if (fileSuppression && suppressionCovers(fileSuppression, ruleId)) return true;
|
|
1157
|
+
const forLine = lineSuppressions.get(line);
|
|
1158
|
+
return forLine !== undefined && suppressionCovers(forLine, ruleId);
|
|
1159
|
+
};
|
|
1160
|
+
const isStyleFile = /\.(css|scss|sass|less)$/.test(file);
|
|
1161
|
+
// `//` is a line comment in code and in SCSS/Sass/Less, but NOT in plain CSS,
|
|
1162
|
+
// HTML, or XML — where it legitimately appears in protocol-relative URLs like
|
|
1163
|
+
// url(//cdn…). Gating it per-file stops the stripper from eating the rest of
|
|
1164
|
+
// those lines (which previously hid real concerns sitting after such a URL).
|
|
1165
|
+
const allowLineComments = !/\.(css|html?|xml|storyboard|xib)$/i.test(file);
|
|
1166
|
+
|
|
1167
|
+
// Strip comments once per line (string literals preserved). The stripped text
|
|
1168
|
+
// drives CSS block tracking, per-line matching, and whole-document matching;
|
|
1169
|
+
// the original line is what gets reported back to the user.
|
|
1170
|
+
const commentState: CommentState = { inBlock: false, inHtml: false };
|
|
1171
|
+
const lines = rawLines.map(l => stripComments(l, commentState, allowLineComments));
|
|
1172
|
+
|
|
1173
|
+
// Pre-filter rules to those applicable to this file, then split by scope so we
|
|
1174
|
+
// don't re-test every rule's fileFilter against every line.
|
|
1175
|
+
const applicable = allRules.filter(r => !r.fileFilter || r.fileFilter.test(file));
|
|
1176
|
+
const lineRules = applicable.filter(r => r.scope !== "document");
|
|
1177
|
+
const docRules = applicable.filter(r => r.scope === "document");
|
|
1178
|
+
|
|
1179
|
+
// Track CSS block context for skipInBlock rules: a stack of block-opening lines
|
|
1180
|
+
// so we can tell whether we're inside @media print, :focus:not(:focus-visible), etc.
|
|
1181
|
+
const blockContext: string[] = [];
|
|
1182
|
+
let braceDepth = 0;
|
|
1183
|
+
const blockStartDepth: number[] = [];
|
|
1184
|
+
|
|
1185
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1186
|
+
const scanLine = lines[i];
|
|
1187
|
+
|
|
1188
|
+
if (isStyleFile) {
|
|
1189
|
+
const opensBlock = scanLine.includes("{");
|
|
1190
|
+
const closesBlock = scanLine.includes("}");
|
|
1191
|
+
if (opensBlock) {
|
|
1192
|
+
// Accumulate context: look back up to 3 lines for the selector/at-rule.
|
|
1193
|
+
let contextLines = scanLine;
|
|
1194
|
+
for (let j = Math.max(0, i - 3); j < i; j++) {
|
|
1195
|
+
if (!lines[j].includes("}") && !lines[j].includes("{")) {
|
|
1196
|
+
contextLines = `${lines[j]} ${contextLines}`;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
blockContext.push(contextLines);
|
|
1200
|
+
blockStartDepth.push(braceDepth);
|
|
1201
|
+
braceDepth++;
|
|
1202
|
+
}
|
|
1203
|
+
if (closesBlock) {
|
|
1204
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
1205
|
+
while (blockStartDepth.length > 0 && blockStartDepth[blockStartDepth.length - 1] >= braceDepth) {
|
|
1206
|
+
blockStartDepth.pop();
|
|
1207
|
+
blockContext.pop();
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
for (const rule of lineRules) {
|
|
1213
|
+
if (rule.regex.test(scanLine)) {
|
|
1214
|
+
const skipInBlock = rule.skipInBlock;
|
|
1215
|
+
if (skipInBlock && isStyleFile) {
|
|
1216
|
+
const inSkippedBlock = blockContext.some((ctx) => skipInBlock.test(ctx));
|
|
1217
|
+
if (inSkippedBlock) continue;
|
|
1218
|
+
}
|
|
1219
|
+
if (isSuppressed(rule.id, i + 1)) continue;
|
|
1220
|
+
matches.push({
|
|
1221
|
+
ruleId: rule.id,
|
|
1222
|
+
engine: "regex",
|
|
1223
|
+
category: rule.category,
|
|
1224
|
+
subcategory: rule.subcategory,
|
|
1225
|
+
type: rule.type,
|
|
1226
|
+
pattern: rule.pattern,
|
|
1227
|
+
line: i + 1,
|
|
1228
|
+
lineContent: rawLines[i].trim(),
|
|
1229
|
+
file,
|
|
1230
|
+
severity: rule.type === "concern" ? severityFor(rule.pattern) : undefined,
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// Document-scoped rules match against the whole comment-stripped source, so
|
|
1237
|
+
// tags that wrap across lines and child/sibling relationships (e.g. a <video>
|
|
1238
|
+
// with a <track>) are visible — things a per-line scan structurally cannot see.
|
|
1239
|
+
if (docRules.length > 0) {
|
|
1240
|
+
const stripped = lines.join("\n");
|
|
1241
|
+
// Offsets of each line start, so a match index maps back to a 1-based line.
|
|
1242
|
+
const lineStarts = [0];
|
|
1243
|
+
for (let k = 0; k < stripped.length; k++) {
|
|
1244
|
+
if (stripped[k] === "\n") lineStarts.push(k + 1);
|
|
1245
|
+
}
|
|
1246
|
+
const lineNumberAt = (index: number): number => {
|
|
1247
|
+
let lo = 0;
|
|
1248
|
+
let hi = lineStarts.length - 1;
|
|
1249
|
+
while (lo < hi) {
|
|
1250
|
+
const mid = (lo + hi + 1) >> 1;
|
|
1251
|
+
if (lineStarts[mid] <= index) lo = mid;
|
|
1252
|
+
else hi = mid - 1;
|
|
1253
|
+
}
|
|
1254
|
+
return lo + 1;
|
|
1255
|
+
};
|
|
1256
|
+
for (const rule of docRules) {
|
|
1257
|
+
// requireAbsent: a file-level signal (e.g. ":hover styles but no :focus
|
|
1258
|
+
// anywhere"). Skip when the "good" pattern is present; otherwise report a
|
|
1259
|
+
// single finding at the first match.
|
|
1260
|
+
if (rule.requireAbsent && rule.requireAbsent.test(stripped)) continue;
|
|
1261
|
+
const flags = rule.regex.flags.includes("g") ? rule.regex.flags : rule.regex.flags + "g";
|
|
1262
|
+
const re = new RegExp(rule.regex.source, flags);
|
|
1263
|
+
let m: RegExpExecArray | null;
|
|
1264
|
+
while ((m = re.exec(stripped)) !== null) {
|
|
1265
|
+
const lineNo = lineNumberAt(m.index);
|
|
1266
|
+
if (isSuppressed(rule.id, lineNo)) {
|
|
1267
|
+
if (rule.requireAbsent) break;
|
|
1268
|
+
if (m.index === re.lastIndex) re.lastIndex++;
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
matches.push({
|
|
1272
|
+
ruleId: rule.id,
|
|
1273
|
+
engine: "regex",
|
|
1274
|
+
category: rule.category,
|
|
1275
|
+
subcategory: rule.subcategory,
|
|
1276
|
+
type: rule.type,
|
|
1277
|
+
pattern: rule.pattern,
|
|
1278
|
+
line: lineNo,
|
|
1279
|
+
lineContent: (rawLines[lineNo - 1] ?? "").trim(),
|
|
1280
|
+
file,
|
|
1281
|
+
severity: rule.type === "concern" ? severityFor(rule.pattern) : undefined,
|
|
1282
|
+
});
|
|
1283
|
+
if (rule.requireAbsent) break; // file-level: one finding is enough
|
|
1284
|
+
if (m.index === re.lastIndex) re.lastIndex++; // never spin on a zero-width match
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
// Interleave document findings with line findings in source order so report
|
|
1288
|
+
// excerpts read top-to-bottom.
|
|
1289
|
+
matches.sort((a, b) => a.line - b.line);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return matches;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// Export rule count for documentation
|
|
1296
|
+
export const RULE_COUNT = allRules.length;
|