impeccable 3.4.0 → 3.6.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.
@@ -35,6 +35,7 @@ export { detectUrl, createBrowserDetector } from './engines/browser/detect-url.m
35
35
  export { detectText, extractStyleBlocks, extractCSSinJS } from './engines/regex/detect-text.mjs';
36
36
  export {
37
37
  walkDir,
38
+ hasScannableExtension,
38
39
  SCANNABLE_EXTENSIONS,
39
40
  SKIP_DIRS,
40
41
  buildImportGraph,
@@ -7,6 +7,38 @@ import { profileFindingsAsync, profileStep, profileStepAsync } from '../../profi
7
7
  import { captureVisualContrastCandidate } from '../visual/screenshot-contrast.mjs';
8
8
  import { checkContentHiddenAtRest } from '../../rules/checks.mjs';
9
9
 
10
+ // On Windows, puppeteer's bundled Chrome lives in a user-writable cache
11
+ // directory. Its GPU process can be denied (STATUS_ACCESS_DENIED) by security
12
+ // software or the GPU sandbox because it launches from an untrusted path.
13
+ // Chrome then crash-loops the GPU process, and each relaunch briefly flashes a
14
+ // compositor surface, the black window users report during `detect <url>`
15
+ // (issue #372). The system-installed Chrome runs from a trusted location with a
16
+ // healthy GPU, so channel:'chrome' avoids the crash entirely; both use hardware
17
+ // GPU, so contrast measurement is unaffected. Scope this to Windows only: other
18
+ // platforms do not have the bug, so they keep the pinned bundled build for
19
+ // consistent measurement across machines. Fall back to bundled when the switch
20
+ // fails (Chrome not installed, or channel resolution fails). If the bundled
21
+ // launch then also fails, surface the original system-Chrome error as the
22
+ // cause so the real failure is not lost.
23
+ async function launchBrowser(puppeteer, { headless = true, args = [] } = {}) {
24
+ let channelError;
25
+ if (process.platform === 'win32') {
26
+ try {
27
+ return await puppeteer.default.launch({ channel: 'chrome', headless, args });
28
+ } catch (err) {
29
+ // System Chrome unavailable or unlaunchable; fall through to the bundled
30
+ // browser, but keep the error in case the fallback fails too.
31
+ channelError = err;
32
+ }
33
+ }
34
+ try {
35
+ return await puppeteer.default.launch({ headless, args });
36
+ } catch (err) {
37
+ if (channelError && err && err.cause === undefined) err.cause = channelError;
38
+ throw err;
39
+ }
40
+ }
41
+
10
42
  // Reveal sweep + invisible-text measurement for the content-hidden-at-rest
11
43
  // rule. Scrolls through the document with instant jumps (bypasses CSS
12
44
  // scroll-behavior: smooth) so IntersectionObserver / scroll reveal handlers
@@ -178,7 +210,7 @@ async function detectUrl(url, options = {}) {
178
210
  phase: 'load',
179
211
  ruleId: 'launch-browser',
180
212
  target: url,
181
- }, () => puppeteer.default.launch({ headless: true, args: launchArgs }));
213
+ }, () => launchBrowser(puppeteer, { headless: options?.headless ?? true, args: launchArgs }));
182
214
  const page = await profileStepAsync(profile, {
183
215
  engine: 'browser',
184
216
  phase: 'load',
@@ -312,7 +344,7 @@ async function createBrowserDetector(options = {}) {
312
344
  throw new Error('puppeteer is required for URL scanning. Install: npm install puppeteer');
313
345
  }
314
346
  const launchArgs = options.launchArgs || (process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : []);
315
- const browser = options.browser || await puppeteer.default.launch({
347
+ const browser = options.browser || await launchBrowser(puppeteer, {
316
348
  headless: options.headless ?? true,
317
349
  args: launchArgs,
318
350
  });
@@ -337,4 +369,4 @@ async function createBrowserDetector(options = {}) {
337
369
  };
338
370
  }
339
371
 
340
- export { runVisualContrastFallback, detectUrl, createBrowserDetector };
372
+ export { runVisualContrastFallback, detectUrl, createBrowserDetector, launchBrowser };
@@ -12,7 +12,8 @@ import { profileFindings, profileStep } from '../../profile/profiler.mjs';
12
12
  // Regex fallback (non-HTML files: CSS, JSX, TSX, etc.)
13
13
  // ---------------------------------------------------------------------------
14
14
 
15
- const hasRounded = (line) => /\brounded(?:-\w+)?\b/.test(line);
15
+ const hasRounded = (line) =>
16
+ /\brounded(?:-\w+)?\b/.test(line.replace(/\brounded-none\b/g, ''));
16
17
  const hasBorderRadius = (line) => /border-radius/i.test(line);
17
18
  const isSafeElement = (line) => /<(?:blockquote|nav[\s>]|pre[\s>]|code[\s>]|a\s|input[\s>]|span[\s>])/i.test(line);
18
19
 
@@ -40,6 +41,221 @@ function shouldRunPageAnalyzers(content, filePath) {
40
41
  return !ext || PAGE_ANALYZER_EXTS.has(ext);
41
42
  }
42
43
 
44
+ const JS_SOURCE_EXTS = new Set(['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs']);
45
+ const REGEX_PREFIX_KEYWORDS = new Set(['await', 'case', 'default', 'delete', 'do', 'else', 'in', 'instanceof', 'new', 'of', 'return', 'throw', 'typeof', 'void', 'yield']);
46
+ const BLOCK_BRACE_PREFIX_KEYWORDS = new Set(['do', 'else', 'finally', 'try']);
47
+
48
+ function isInsideOpeningJsxTag(source) {
49
+ const tagStart = source.lastIndexOf('<');
50
+ if (tagStart === -1 || !/^<[A-Za-z][\w.:-]*/.test(source.slice(tagStart))) return false;
51
+
52
+ let quote = '';
53
+ for (let cursor = tagStart + 1; cursor < source.length; cursor++) {
54
+ const char = source[cursor];
55
+ if (quote) {
56
+ if (char === '\\') cursor++;
57
+ else if (char === quote) quote = '';
58
+ } else if (char === "'" || char === '"') {
59
+ quote = char;
60
+ } else if (char === '>') {
61
+ return false;
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+
67
+ /**
68
+ * Blank JavaScript comments without moving any following source. Regex
69
+ * findings keep their original line numbers, while prose examples inside
70
+ * comments cannot masquerade as rendered markup.
71
+ */
72
+ function stripJsComments(content, options = {}) {
73
+ let state = 'code';
74
+ let output = '';
75
+ let lastSignificant = '';
76
+ let previousSignificant = '';
77
+ let antePreviousSignificant = '';
78
+ let currentWord = '';
79
+ let currentWordPrefix = '';
80
+ let wordSeparated = false;
81
+ let regexCharClass = false;
82
+ let jsxExpressionDepth = 0;
83
+ let lastClosedBraceKind = '';
84
+ const braceKinds = [];
85
+ const templateExpressionDepths = [];
86
+
87
+ const braceKind = (startsJsxExpression = false) => (
88
+ !startsJsxExpression && (
89
+ !lastSignificant ||
90
+ lastSignificant === ')' ||
91
+ lastSignificant === ';' ||
92
+ lastSignificant === '}' ||
93
+ (previousSignificant === '=' && lastSignificant === '>') ||
94
+ BLOCK_BRACE_PREFIX_KEYWORDS.has(currentWord)
95
+ ) ? 'block' : 'expression'
96
+ );
97
+
98
+ const recordSignificant = (char) => {
99
+ if (/\s/.test(char)) {
100
+ wordSeparated = true;
101
+ return;
102
+ }
103
+ const isWordChar = /[\w$]/.test(char);
104
+ if (isWordChar && (wordSeparated || !currentWord)) {
105
+ currentWord = '';
106
+ currentWordPrefix = lastSignificant;
107
+ } else if (!isWordChar) {
108
+ currentWordPrefix = '';
109
+ }
110
+ wordSeparated = false;
111
+ antePreviousSignificant = previousSignificant;
112
+ previousSignificant = lastSignificant;
113
+ lastSignificant = char;
114
+ currentWord = isWordChar ? currentWord + char : '';
115
+ };
116
+
117
+ for (let i = 0; i < content.length; i++) {
118
+ const char = content[i];
119
+ const next = content[i + 1];
120
+
121
+ if (state === 'line-comment') {
122
+ if (char === '\n') {
123
+ output += char;
124
+ state = 'code';
125
+ } else {
126
+ output += ' ';
127
+ }
128
+ continue;
129
+ }
130
+
131
+ if (state === 'block-comment') {
132
+ if (char === '*' && next === '/') {
133
+ output += ' ';
134
+ i++;
135
+ state = 'code';
136
+ } else {
137
+ output += char === '\n' ? '\n' : ' ';
138
+ }
139
+ continue;
140
+ }
141
+
142
+ if (state === 'regex') {
143
+ output += char;
144
+ if (char === '\\' && next) {
145
+ output += next;
146
+ i++;
147
+ } else if (char === '[') {
148
+ regexCharClass = true;
149
+ } else if (char === ']') {
150
+ regexCharClass = false;
151
+ } else if (char === '/' && !regexCharClass) {
152
+ state = 'code';
153
+ recordSignificant('/');
154
+ }
155
+ continue;
156
+ }
157
+
158
+ if (state === 'template' && char === '$' && next === '{') {
159
+ output += '${';
160
+ i++;
161
+ recordSignificant('$');
162
+ recordSignificant('{');
163
+ templateExpressionDepths.push(1);
164
+ braceKinds.push('expression');
165
+ if (jsxExpressionDepth) jsxExpressionDepth++;
166
+ state = 'code';
167
+ continue;
168
+ }
169
+
170
+ if (state !== 'code') {
171
+ output += char;
172
+ if (char === '\\' && next) {
173
+ output += next;
174
+ i++;
175
+ } else if (
176
+ (state === 'single-quote' && char === "'") ||
177
+ (state === 'double-quote' && char === '"') ||
178
+ (state === 'template' && char === '`')
179
+ ) {
180
+ state = 'code';
181
+ recordSignificant(char);
182
+ }
183
+ continue;
184
+ }
185
+
186
+ const jsxUrlSeparator = options.jsx && char === '/' && next === '/' &&
187
+ jsxExpressionDepth === 0 &&
188
+ (output.endsWith('http:') ||
189
+ output.endsWith('https:') ||
190
+ (/<[A-Za-z](?:[^>]*[^/])?>[^<]*$/.test(output.slice(output.lastIndexOf('\n') + 1)) &&
191
+ /^[\w.-]+\.[A-Za-z]{2,}(?=[:/?#\s<]|$)/.test(content.slice(i + 2))));
192
+ const afterPostfixUpdate = (lastSignificant === '+' || lastSignificant === '-') &&
193
+ previousSignificant === lastSignificant &&
194
+ antePreviousSignificant !== lastSignificant;
195
+ if (char === '/' && next === '/' && jsxUrlSeparator) {
196
+ output += '//';
197
+ i++;
198
+ recordSignificant('/');
199
+ recordSignificant('/');
200
+ } else if (char === '/' && next === '/') {
201
+ output += ' ';
202
+ i++;
203
+ state = 'line-comment';
204
+ } else if (char === '/' && next === '*') {
205
+ output += ' ';
206
+ i++;
207
+ state = 'block-comment';
208
+ } else if (templateExpressionDepths.length && char === '{') {
209
+ output += char;
210
+ templateExpressionDepths[templateExpressionDepths.length - 1]++;
211
+ braceKinds.push(braceKind());
212
+ if (jsxExpressionDepth) jsxExpressionDepth++;
213
+ recordSignificant(char);
214
+ } else if (templateExpressionDepths.length && char === '}') {
215
+ output += char;
216
+ const depthIndex = templateExpressionDepths.length - 1;
217
+ templateExpressionDepths[depthIndex]--;
218
+ lastClosedBraceKind = braceKinds.pop() || '';
219
+ if (jsxExpressionDepth) jsxExpressionDepth--;
220
+ recordSignificant(char);
221
+ if (templateExpressionDepths[depthIndex] === 0) {
222
+ templateExpressionDepths.pop();
223
+ state = 'template';
224
+ }
225
+ } else if (
226
+ char === '/' &&
227
+ (!lastSignificant ||
228
+ (/[=([{!?:;,&|+\-*%^~<>]/.test(lastSignificant) && !afterPostfixUpdate) ||
229
+ (lastSignificant === '}' && lastClosedBraceKind === 'block') ||
230
+ (previousSignificant === '=' && lastSignificant === '>') ||
231
+ (currentWordPrefix !== '.' && REGEX_PREFIX_KEYWORDS.has(currentWord)))
232
+ ) {
233
+ output += char;
234
+ state = 'regex';
235
+ regexCharClass = false;
236
+ } else {
237
+ output += char;
238
+ const startsJsxExpression = options.jsx && char === '{' && jsxExpressionDepth === 0 &&
239
+ (/<[A-Za-z](?:[^>]*[^/])?>[^<]*$/.test(output.slice(output.lastIndexOf('\n') + 1, -1)) ||
240
+ isInsideOpeningJsxTag(output.slice(0, -1)));
241
+ if (char === '{') braceKinds.push(braceKind(startsJsxExpression));
242
+ else if (char === '}') lastClosedBraceKind = braceKinds.pop() || '';
243
+ if (char === '{' && (jsxExpressionDepth || startsJsxExpression)) jsxExpressionDepth++;
244
+ else if (char === '}' && jsxExpressionDepth) jsxExpressionDepth--;
245
+ recordSignificant(char);
246
+ if (char === "'") state = 'single-quote';
247
+ else if (char === '"') state = 'double-quote';
248
+ else if (char === '`') state = 'template';
249
+ }
250
+ }
251
+
252
+ return output;
253
+ }
254
+
255
+ function stripCssComments(content) {
256
+ return content.replace(/\/\*[\s\S]*?\*\//g, comment => comment.replace(/[^\n]/g, ' '));
257
+ }
258
+
43
259
  function firstOverusedGoogleFont(text) {
44
260
  return extractGoogleFontFamilies(text).find(f => OVERUSED_FONTS.has(f)) || '';
45
261
  }
@@ -209,25 +425,28 @@ const REGEX_MATCHERS = [
209
425
  },
210
426
  fmt: (m) => `cubic-bezier(${m[1]}, ${m[2]}, ${m[3]}, ${m[4]})` },
211
427
  // --- Layout property transition ---
212
- { id: 'layout-transition', regex: /transition\s*:\s*([^;{}]+)/gi,
428
+ // JSX inline style objects use comma-delimited quoted values, not semicolons (issue #548).
429
+ { id: 'layout-transition', regex: /transition\s*:\s*(?:(['"])((?:(?!\1)[^\\]|\\.)*)\1|([^;{}]+))/gi,
213
430
  test: (m) => {
214
- const val = m[1].toLowerCase();
431
+ const val = (m[2] ?? m[3] ?? '').toLowerCase();
215
432
  if (/\ball\b/.test(val)) return false;
216
433
  return /\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding\b|\bmargin\b/.test(val);
217
434
  },
218
435
  fmt: (m) => {
219
- const found = m[1].match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
220
- return `transition: ${found ? found.join(', ') : m[1].trim()}`;
436
+ const raw = m[2] ?? m[3] ?? '';
437
+ const found = raw.match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
438
+ return `transition: ${found ? found.join(', ') : raw.trim()}`;
221
439
  } },
222
- { id: 'layout-transition', regex: /transition-property\s*:\s*([^;{}]+)/gi,
440
+ { id: 'layout-transition', regex: /transition-property\s*:\s*(?:(['"])((?:(?!\1)[^\\]|\\.)*)\1|([^;{}]+))/gi,
223
441
  test: (m) => {
224
- const val = m[1].toLowerCase();
442
+ const val = (m[2] ?? m[3] ?? '').toLowerCase();
225
443
  if (/\ball\b/.test(val)) return false;
226
444
  return /\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding\b|\bmargin\b/.test(val);
227
445
  },
228
446
  fmt: (m) => {
229
- const found = m[1].match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
230
- return `transition-property: ${found ? found.join(', ') : m[1].trim()}`;
447
+ const raw = m[2] ?? m[3] ?? '';
448
+ const found = raw.match(/\b(?:(?:max|min)-)?(?:width|height)\b|\bpadding(?:-(?:top|right|bottom|left))?\b|\bmargin(?:-(?:top|right|bottom|left))?\b/gi);
449
+ return `transition-property: ${found ? found.join(', ') : raw.trim()}`;
231
450
  } },
232
451
  // --- Broken image: src="" or src="#" or src=" " ---
233
452
  { id: 'broken-image', regex: /<img\b[^>]*?\bsrc\s*=\s*(?:""|''|"\s+"|'\s+'|"#"|'#')/gi,
@@ -240,24 +459,6 @@ const REGEX_MATCHERS = [
240
459
  ];
241
460
 
242
461
  const REGEX_ANALYZERS = [
243
- // Single font
244
- (content, filePath) => {
245
- const fontFamilyRe = /font-family\s*:\s*([^;}]+)/gi;
246
- const fonts = new Set();
247
- let m;
248
- while ((m = fontFamilyRe.exec(content)) !== null) {
249
- for (const f of m[1].split(',').map(f => f.trim().replace(/^['"]|['"]$/g, '').toLowerCase())) {
250
- if (f && !GENERIC_FONTS.has(f)) fonts.add(f);
251
- }
252
- }
253
- for (const f of extractGoogleFontFamilies(content)) fonts.add(f);
254
- if (fonts.size !== 1 || content.split('\n').length < 20) return [];
255
- const name = [...fonts][0];
256
- const lines = content.split('\n');
257
- let line = 1;
258
- for (let i = 0; i < lines.length; i++) { if (lines[i].toLowerCase().includes(name)) { line = i + 1; break; } }
259
- return [finding('single-font', filePath, `only font used is ${name}`, line)];
260
- },
261
462
  // Flat type hierarchy
262
463
  (content, filePath) => {
263
464
  const sizes = new Set();
@@ -545,18 +746,198 @@ function extractStyleBlocks(content, ext) {
545
746
 
546
747
  const CSS_IN_JS_EXTENSIONS = new Set(['.js', '.ts', '.jsx', '.tsx']);
547
748
 
749
+ function findQuotedStringEnd(content, start, quote) {
750
+ for (let cursor = start + 1; cursor < content.length; cursor++) {
751
+ if (content[cursor] === '\\') cursor++;
752
+ else if (content[cursor] === quote) return cursor;
753
+ }
754
+ return -1;
755
+ }
756
+
757
+ function findRegexLiteralEnd(content, start) {
758
+ let inCharacterClass = false;
759
+ for (let cursor = start + 1; cursor < content.length; cursor++) {
760
+ const char = content[cursor];
761
+ if (char === '\\') {
762
+ cursor++;
763
+ } else if (char === '[') {
764
+ inCharacterClass = true;
765
+ } else if (char === ']') {
766
+ inCharacterClass = false;
767
+ } else if (char === '/' && !inCharacterClass) {
768
+ while (/[A-Za-z]/.test(content[cursor + 1] || '')) cursor++;
769
+ return cursor;
770
+ } else if (char === '\n' || char === '\r') {
771
+ return -1;
772
+ }
773
+ }
774
+ return -1;
775
+ }
776
+
777
+ function findTemplateExpressionEnd(content, start) {
778
+ let depth = 1;
779
+ let lastSignificant = '';
780
+ let previousSignificant = '';
781
+ let antePreviousSignificant = '';
782
+ let currentWord = '';
783
+ let currentWordPrefix = '';
784
+ let wordSeparated = false;
785
+ let lastClosedBraceKind = '';
786
+ const braceKinds = [];
787
+
788
+ const braceKind = () => (
789
+ lastSignificant === ')' ||
790
+ lastSignificant === ';' ||
791
+ lastSignificant === '}' ||
792
+ (previousSignificant === '=' && lastSignificant === '>') ||
793
+ BLOCK_BRACE_PREFIX_KEYWORDS.has(currentWord)
794
+ ? 'block'
795
+ : 'expression'
796
+ );
797
+
798
+ const recordSignificant = (char) => {
799
+ if (/\s/.test(char)) {
800
+ wordSeparated = true;
801
+ return;
802
+ }
803
+ const isWordChar = /[\w$]/.test(char);
804
+ if (isWordChar && (wordSeparated || !currentWord)) {
805
+ currentWord = '';
806
+ currentWordPrefix = lastSignificant;
807
+ } else if (!isWordChar) {
808
+ currentWordPrefix = '';
809
+ }
810
+ wordSeparated = false;
811
+ antePreviousSignificant = previousSignificant;
812
+ previousSignificant = lastSignificant;
813
+ lastSignificant = char;
814
+ currentWord = isWordChar ? currentWord + char : '';
815
+ };
816
+
817
+ for (let cursor = start; cursor < content.length; cursor++) {
818
+ const char = content[cursor];
819
+ const next = content[cursor + 1];
820
+ const afterPostfixUpdate = (lastSignificant === '+' || lastSignificant === '-') &&
821
+ previousSignificant === lastSignificant &&
822
+ antePreviousSignificant !== lastSignificant;
823
+ if (char === "'" || char === '"') {
824
+ cursor = findQuotedStringEnd(content, cursor, char);
825
+ if (cursor === -1) return -1;
826
+ recordSignificant(')');
827
+ } else if (char === '/' && next === '/') {
828
+ const lineEnd = content.indexOf('\n', cursor + 2);
829
+ if (lineEnd === -1) return -1;
830
+ cursor = lineEnd;
831
+ } else if (char === '/' && next === '*') {
832
+ const commentEnd = content.indexOf('*/', cursor + 2);
833
+ if (commentEnd === -1) return -1;
834
+ cursor = commentEnd + 1;
835
+ } else if (
836
+ char === '/' &&
837
+ (!lastSignificant ||
838
+ (/[=([{!?:;,&|+\-*%^~<>]/.test(lastSignificant) && !afterPostfixUpdate) ||
839
+ (lastSignificant === '}' && lastClosedBraceKind === 'block') ||
840
+ (previousSignificant === '=' && lastSignificant === '>') ||
841
+ (currentWordPrefix !== '.' && REGEX_PREFIX_KEYWORDS.has(currentWord)))
842
+ ) {
843
+ cursor = findRegexLiteralEnd(content, cursor);
844
+ if (cursor === -1) return -1;
845
+ recordSignificant(')');
846
+ } else if (char === '`') {
847
+ cursor = findTemplateLiteralEnd(content, cursor);
848
+ if (cursor === -1) return -1;
849
+ recordSignificant(')');
850
+ } else if (char === '{') {
851
+ depth++;
852
+ braceKinds.push(braceKind());
853
+ recordSignificant(char);
854
+ } else if (char === '}') {
855
+ depth--;
856
+ if (depth === 0) return cursor;
857
+ lastClosedBraceKind = braceKinds.pop() || '';
858
+ recordSignificant(char);
859
+ } else {
860
+ recordSignificant(char);
861
+ }
862
+ }
863
+ return -1;
864
+ }
865
+
866
+ function findTemplateLiteralEnd(content, start) {
867
+ for (let cursor = start + 1; cursor < content.length; cursor++) {
868
+ const char = content[cursor];
869
+ if (char === '\\') {
870
+ cursor++;
871
+ } else if (char === '`') {
872
+ return cursor;
873
+ } else if (char === '$' && content[cursor + 1] === '{') {
874
+ cursor = findTemplateExpressionEnd(content, cursor + 2);
875
+ if (cursor === -1) return -1;
876
+ }
877
+ }
878
+ return -1;
879
+ }
880
+
881
+ function findCSSinJSTemplates(content) {
882
+ const templates = [];
883
+ const tagRe = /\b(?:styled(?:\.\w+|\([^)]+\))|css)/g;
884
+ let match;
885
+ while ((match = tagRe.exec(content)) !== null) {
886
+ let cursor = match.index + match[0].length;
887
+ while (/\s/.test(content[cursor] || '')) cursor++;
888
+
889
+ if (content[cursor] === '<') {
890
+ let depth = 0;
891
+ while (cursor < content.length) {
892
+ const char = content[cursor];
893
+ if (char === '<') depth++;
894
+ else if (char === '>' && content[cursor - 1] !== '=') depth--;
895
+ cursor++;
896
+ if (depth === 0) break;
897
+ }
898
+ if (depth !== 0) continue;
899
+ while (/\s/.test(content[cursor] || '')) cursor++;
900
+ }
901
+
902
+ if (content[cursor] !== '`') continue;
903
+ const contentStart = cursor + 1;
904
+ cursor = findTemplateLiteralEnd(content, cursor);
905
+ if (cursor === -1) continue;
906
+
907
+ templates.push({
908
+ tagStart: match.index,
909
+ contentStart,
910
+ contentEnd: cursor,
911
+ });
912
+ tagRe.lastIndex = cursor + 1;
913
+ }
914
+ return templates;
915
+ }
916
+
548
917
  function extractCSSinJS(content, ext) {
549
918
  ext = ext.toLowerCase();
550
919
  if (!CSS_IN_JS_EXTENSIONS.has(ext)) return [];
551
- const blocks = [];
552
- const re = /(?:styled(?:\.\w+|\([^)]+\))|css)\s*`([\s\S]*?)`/g;
553
- let m;
554
- while ((m = re.exec(content)) !== null) {
555
- const before = content.substring(0, m.index);
920
+ return findCSSinJSTemplates(content).map((template) => {
921
+ const before = content.substring(0, template.tagStart);
556
922
  const startLine = before.split('\n').length;
557
- blocks.push({ content: m[1], startLine });
923
+ return {
924
+ content: content.slice(template.contentStart, template.contentEnd),
925
+ startLine,
926
+ };
927
+ });
928
+ }
929
+
930
+ function stripCssInJsComments(content, ext) {
931
+ if (!CSS_IN_JS_EXTENSIONS.has(ext.toLowerCase())) return content;
932
+ const templates = findCSSinJSTemplates(content);
933
+ let output = '';
934
+ let cursor = 0;
935
+ for (const template of templates) {
936
+ output += content.slice(cursor, template.contentStart);
937
+ output += stripCssComments(content.slice(template.contentStart, template.contentEnd));
938
+ cursor = template.contentEnd;
558
939
  }
559
- return blocks;
940
+ return output + content.slice(cursor);
560
941
  }
561
942
 
562
943
  function runRegexMatchers(lines, filePath, lineOffset = 0, blockContext = null, options = {}) {
@@ -625,10 +1006,11 @@ const TEXT_CONTENT_ANALYZER_IDS = [
625
1006
  function runTextContentAnalyzers(content, filePath, options = {}) {
626
1007
  const profile = options?.profile;
627
1008
  if (!shouldRunPageAnalyzers(content, filePath)) return [];
628
- // The 3 text-content analyzers are at indices 3-5 in REGEX_ANALYZERS.
1009
+ // The 3 text-content analyzers are at indices 2-4 in REGEX_ANALYZERS
1010
+ // (single-font's removal on 2026-07-29 shifted every index down one).
629
1011
  const findings = [];
630
1012
  for (let i = 0; i < TEXT_CONTENT_ANALYZER_IDS.length; i++) {
631
- const analyzer = REGEX_ANALYZERS[3 + i];
1013
+ const analyzer = REGEX_ANALYZERS[2 + i];
632
1014
  const ruleId = TEXT_CONTENT_ANALYZER_IDS[i];
633
1015
  findings.push(...profileFindings(profile, {
634
1016
  engine: 'regex',
@@ -643,8 +1025,12 @@ function runTextContentAnalyzers(content, filePath, options = {}) {
643
1025
  function detectText(content, filePath, options = {}) {
644
1026
  const profile = options?.profile;
645
1027
  const findings = [];
646
- const lines = content.split('\n');
647
1028
  const ext = extFromFilePath(filePath);
1029
+ const commentStrippedSource = JS_SOURCE_EXTS.has(ext) ? stripJsComments(content, {
1030
+ jsx: ext === '.js' || ext === '.jsx' || ext === '.tsx',
1031
+ }) : content;
1032
+ const source = stripCssInJsComments(commentStrippedSource, ext);
1033
+ const lines = source.split('\n');
648
1034
 
649
1035
  // Run regex matchers on the full file content (catches Tailwind classes, inline styles)
650
1036
  // Enable block context for CSS files where related properties span multiple lines
@@ -677,8 +1063,8 @@ function detectText(content, filePath, options = {}) {
677
1063
  phase: 'source',
678
1064
  ruleId: 'codex-grid-background',
679
1065
  target: filePath,
680
- }, () => scanCssTextForGridBackground(content).map(hit => {
681
- const line = content.substring(0, hit.index).split('\n').length;
1066
+ }, () => scanCssTextForGridBackground(source).map(hit => {
1067
+ const line = source.substring(0, hit.index).split('\n').length;
682
1068
  return finding('codex-grid-background', filePath, hit.snippet, line);
683
1069
  })));
684
1070
 
@@ -714,16 +1100,17 @@ function detectText(content, filePath, options = {}) {
714
1100
  phase: 'extract',
715
1101
  ruleId: 'css-in-js',
716
1102
  target: filePath,
717
- }, () => extractCSSinJS(content, ext))
718
- : extractCSSinJS(content, ext);
1103
+ }, () => extractCSSinJS(source, ext))
1104
+ : extractCSSinJS(source, ext);
719
1105
  for (const block of cssJsBlocks) {
720
- const blockLines = block.content.split('\n');
1106
+ const blockContent = stripCssComments(block.content);
1107
+ const blockLines = blockContent.split('\n');
721
1108
  findings.push(...runRegexMatchers(blockLines, filePath, block.startLine - 1, true, {
722
1109
  profile,
723
1110
  phase: 'css-in-js',
724
1111
  }));
725
- findings.push(...scanInsetStripeCss(block.content, filePath, block.startLine - 1));
726
- findings.push(...pseudoStripeFindings(block.content, block.startLine - 1));
1112
+ findings.push(...scanInsetStripeCss(blockContent, filePath, block.startLine - 1));
1113
+ findings.push(...pseudoStripeFindings(blockContent, block.startLine - 1));
727
1114
  }
728
1115
 
729
1116
  if (options?.designSystem) {
@@ -749,7 +1136,6 @@ function detectText(content, filePath, options = {}) {
749
1136
  // Page-level analyzers only run on full pages
750
1137
  if (shouldRunPageAnalyzers(content, filePath)) {
751
1138
  const analyzerIds = [
752
- 'single-font',
753
1139
  'flat-type-hierarchy',
754
1140
  'monotonous-spacing',
755
1141
  'em-dash-overuse',
@@ -226,6 +226,10 @@ const STATIC_INHERITED_PROPS = new Set([
226
226
  'color', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'fontVariant',
227
227
  'lineHeight', 'letterSpacing', 'textTransform', 'textAlign', 'hyphens',
228
228
  'webkitHyphens',
229
+ // visibility inherits in real CSS, and the invisible-at-rest contrast skip
230
+ // relies on descendants of a hidden container computing as hidden. A child
231
+ // that declares `visibility: visible` still overrides the inherited value.
232
+ 'visibility',
229
233
  ]);
230
234
 
231
235
  const STATIC_DEFAULT_STYLE = {
@@ -278,6 +282,7 @@ const STATIC_DEFAULT_STYLE = {
278
282
  marginLeft: '0px',
279
283
  position: 'static',
280
284
  visibility: 'visible',
285
+ opacity: '1',
281
286
  top: 'auto',
282
287
  right: 'auto',
283
288
  bottom: 'auto',
@@ -334,6 +339,7 @@ const STATIC_PROP_MAP = {
334
339
  'margin-left': 'marginLeft',
335
340
  'position': 'position',
336
341
  'visibility': 'visibility',
342
+ 'opacity': 'opacity',
337
343
  'top': 'top',
338
344
  'right': 'right',
339
345
  'bottom': 'bottom',
@@ -952,7 +958,10 @@ function collectStaticCssText(root, fileDir, profile, filePath, modules) {
952
958
  const rel = link.attribs?.rel || '';
953
959
  const href = link.attribs?.href || '';
954
960
  if (!/\bstylesheet\b/i.test(rel) || !href || /^(https?:)?\/\//i.test(href)) continue;
955
- const cssPath = path.resolve(fileDir, href);
961
+ // Cache-busting hrefs (styles.css?v=3) resolve to the file, not to a
962
+ // literal path with the query in it; a versioned link otherwise made the
963
+ // whole stylesheet invisible to every element-level check.
964
+ const cssPath = path.resolve(fileDir, href.split(/[?#]/)[0]);
956
965
  try {
957
966
  const css = profileStep(profile, {
958
967
  engine: 'static-html',