impeccable 3.2.1 → 3.3.1
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/README.md +2 -2
- package/README.npm.md +2 -2
- package/README.repo.md +30 -9
- package/cli/bin/commands/ignores.mjs +27 -6
- package/cli/bin/commands/skills.mjs +168 -22
- package/cli/engine/browser/injected/index.mjs +84 -6
- package/cli/engine/cli/main.mjs +143 -26
- package/cli/engine/design-system.mjs +181 -12
- package/cli/engine/detect-antipatterns-browser.js +2877 -138
- package/cli/engine/engines/browser/detect-url.mjs +67 -4
- package/cli/engine/engines/regex/detect-text.mjs +266 -70
- package/cli/engine/engines/static-html/css-cascade.mjs +161 -5
- package/cli/engine/engines/static-html/detect-html.mjs +18 -5
- package/cli/engine/findings.mjs +7 -1
- package/cli/engine/registry/antipatterns.mjs +142 -37
- package/cli/engine/rules/checks.mjs +2706 -127
- package/cli/engine/shared/constants.mjs +11 -0
- package/cli/lib/download-providers.js +2 -0
- package/cli/lib/impeccable-config.mjs +20 -5
- package/package.json +7 -19
|
@@ -3,9 +3,36 @@ import path from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { finding } from '../../findings.mjs';
|
|
6
|
-
import { filterByProviders } from '../../registry/antipatterns.mjs';
|
|
7
6
|
import { profileFindingsAsync, profileStep, profileStepAsync } from '../../profile/profiler.mjs';
|
|
8
7
|
import { captureVisualContrastCandidate } from '../visual/screenshot-contrast.mjs';
|
|
8
|
+
import { checkContentHiddenAtRest } from '../../rules/checks.mjs';
|
|
9
|
+
|
|
10
|
+
// Reveal sweep + invisible-text measurement for the content-hidden-at-rest
|
|
11
|
+
// rule. Scrolls through the document with instant jumps (bypasses CSS
|
|
12
|
+
// scroll-behavior: smooth) so IntersectionObserver / scroll reveal handlers
|
|
13
|
+
// get every chance to fire, returns to the top, lets transitions settle,
|
|
14
|
+
// then measures how much text still renders invisible. A healthy
|
|
15
|
+
// reveal-on-scroll page drops to ~0 after the sweep; a page whose reveal
|
|
16
|
+
// script died keeps most of its text at opacity 0.
|
|
17
|
+
async function measureContentHiddenAfterReveal(page) {
|
|
18
|
+
await page.evaluate(async () => {
|
|
19
|
+
const step = Math.max(200, Math.floor(window.innerHeight * 0.7));
|
|
20
|
+
const max = Math.max(
|
|
21
|
+
document.documentElement.scrollHeight || 0,
|
|
22
|
+
document.body?.scrollHeight || 0,
|
|
23
|
+
);
|
|
24
|
+
for (let y = 0; y <= max; y += step) {
|
|
25
|
+
window.scrollTo({ top: y, left: 0, behavior: 'instant' });
|
|
26
|
+
await new Promise(resolve => requestAnimationFrame(() => setTimeout(resolve, 40)));
|
|
27
|
+
}
|
|
28
|
+
window.scrollTo({ top: 0, left: 0, behavior: 'instant' });
|
|
29
|
+
await new Promise(resolve => setTimeout(resolve, 700));
|
|
30
|
+
});
|
|
31
|
+
return page.evaluate(() => {
|
|
32
|
+
if (typeof window.impeccableMeasureHiddenText !== 'function') return null;
|
|
33
|
+
return window.impeccableMeasureHiddenText();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
9
36
|
|
|
10
37
|
function serializeDesignSystemForBrowser(designSystem) {
|
|
11
38
|
if (!designSystem?.present) return null;
|
|
@@ -158,6 +185,19 @@ async function detectUrl(url, options = {}) {
|
|
|
158
185
|
ruleId: 'new-page',
|
|
159
186
|
target: url,
|
|
160
187
|
}, () => browser.newPage());
|
|
188
|
+
|
|
189
|
+
// Uncaught exceptions and parse errors surface as pageerror events. The
|
|
190
|
+
// listener must attach before goto: a syntax error fires during the
|
|
191
|
+
// initial parse, long before the load event. Dedupe by message; a single
|
|
192
|
+
// broken loop can otherwise throw hundreds of identical errors.
|
|
193
|
+
const pageErrors = [];
|
|
194
|
+
if (options?.scriptErrors !== false) {
|
|
195
|
+
page.on('pageerror', (err) => {
|
|
196
|
+
const message = String(err?.message || err).split('\n')[0].trim().slice(0, 160);
|
|
197
|
+
if (message && !pageErrors.includes(message)) pageErrors.push(message);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
161
201
|
let results = [];
|
|
162
202
|
try {
|
|
163
203
|
await profileStepAsync(profile, {
|
|
@@ -213,9 +253,29 @@ async function detectUrl(url, options = {}) {
|
|
|
213
253
|
return window.impeccableDetect({ decorate: false, serialize: true });
|
|
214
254
|
});
|
|
215
255
|
return serializedGroups.flatMap(({ findings }) =>
|
|
216
|
-
findings.map(f => ({ id: f.type, snippet: f.detail, ignoreValue: f.ignoreValue || '' }))
|
|
256
|
+
findings.map(f => ({ id: f.type, snippet: f.detail, ignoreValue: f.ignoreValue || '', severity: f.severity || '' }))
|
|
217
257
|
);
|
|
218
258
|
});
|
|
259
|
+
// Content invisible at rest: reveal sweep, then re-measure. Runs after
|
|
260
|
+
// the main scan (which must see the true at-rest state) and before the
|
|
261
|
+
// visual contrast fallback (the sweep restores scroll to the top).
|
|
262
|
+
if (options?.contentHidden !== false) {
|
|
263
|
+
const hiddenFindings = await profileFindingsAsync(profile, {
|
|
264
|
+
engine: 'browser',
|
|
265
|
+
phase: 'scan',
|
|
266
|
+
ruleId: 'content-hidden-at-rest',
|
|
267
|
+
target: url,
|
|
268
|
+
}, async () => {
|
|
269
|
+
const measured = await measureContentHiddenAfterReveal(page);
|
|
270
|
+
return measured ? checkContentHiddenAtRest(measured) : [];
|
|
271
|
+
});
|
|
272
|
+
results.push(...hiddenFindings);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
for (const message of pageErrors.slice(0, 3)) {
|
|
276
|
+
results.push({ id: 'script-error', snippet: message });
|
|
277
|
+
}
|
|
278
|
+
|
|
219
279
|
const visualFindings = await runVisualContrastFallback(page, serializedGroups, options, profile, url);
|
|
220
280
|
results.push(...visualFindings);
|
|
221
281
|
} finally {
|
|
@@ -234,11 +294,14 @@ async function detectUrl(url, options = {}) {
|
|
|
234
294
|
}, () => browser.close());
|
|
235
295
|
}
|
|
236
296
|
}
|
|
237
|
-
return
|
|
297
|
+
return results.map(f => {
|
|
238
298
|
const item = finding(f.id, url, f.snippet);
|
|
239
299
|
if (f.ignoreValue) item.ignoreValue = f.ignoreValue;
|
|
300
|
+
// Per-finding severity promotion (e.g. hero-region pulsing dot)
|
|
301
|
+
// overrides the registry default carried by finding().
|
|
302
|
+
if (f.severity && f.severity !== item.severity) item.severity = f.severity;
|
|
240
303
|
return item;
|
|
241
|
-
})
|
|
304
|
+
});
|
|
242
305
|
}
|
|
243
306
|
|
|
244
307
|
async function createBrowserDetector(options = {}) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { GENERIC_FONTS, OVERUSED_FONTS } from '../../shared/constants.mjs';
|
|
1
|
+
import { GENERIC_FONTS, OVERUSED_FONTS, EM_DASH_FLOOR, EM_DASH_CHARS_PER_DASH } from '../../shared/constants.mjs';
|
|
2
2
|
import { isNeutralColor } from '../../shared/color.mjs';
|
|
3
3
|
import { extractGoogleFontFamilies } from '../../shared/fonts.mjs';
|
|
4
4
|
import { checkSourceDesignSystem } from '../../design-system.mjs';
|
|
5
|
+
import { scanCssTextForGlow, scanCssTextForGridBackground, scanCssTextForMarquee, scanCssTextForRadialHalo } from '../../rules/checks.mjs';
|
|
5
6
|
import { isFullPage } from '../../shared/page.mjs';
|
|
6
7
|
import { applyInlineIgnores } from '../../shared/inline-ignores.mjs';
|
|
7
8
|
import { finding } from '../../findings.mjs';
|
|
8
|
-
import { filterByProviders } from '../../registry/antipatterns.mjs';
|
|
9
9
|
import { profileFindings, profileStep } from '../../profile/profiler.mjs';
|
|
10
10
|
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
@@ -16,6 +16,7 @@ const hasRounded = (line) => /\brounded(?:-\w+)?\b/.test(line);
|
|
|
16
16
|
const hasBorderRadius = (line) => /border-radius/i.test(line);
|
|
17
17
|
const isSafeElement = (line) => /<(?:blockquote|nav[\s>]|pre[\s>]|code[\s>]|a\s|input[\s>]|span[\s>])/i.test(line);
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
/** Strip HTML to plain text — drops script/style/comments/tags so
|
|
20
21
|
* content-text analyzers don't false-positive on code or CSS. */
|
|
21
22
|
function stripHtmlToText(html) {
|
|
@@ -43,25 +44,96 @@ function firstOverusedGoogleFont(text) {
|
|
|
43
44
|
return extractGoogleFontFamilies(text).find(f => OVERUSED_FONTS.has(f)) || '';
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
// CSS named colors whose channels are equal (achromatic). Anything outside
|
|
48
|
+
// this set falls through to the format parsers, and an unrecognized spelling
|
|
49
|
+
// stays non-neutral so a real accent is never skipped.
|
|
50
|
+
const NEUTRAL_COLOR_KEYWORDS = new Set([
|
|
51
|
+
'transparent', 'currentcolor',
|
|
52
|
+
'black', 'white', 'gray', 'grey', 'silver',
|
|
53
|
+
'dimgray', 'dimgrey', 'darkgray', 'darkgrey', 'lightgray', 'lightgrey',
|
|
54
|
+
'gainsboro', 'whitesmoke',
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
function hexChannels(color) {
|
|
58
|
+
const long = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:[0-9a-f]{2})?$/i);
|
|
59
|
+
if (long) return [parseInt(long[1], 16), parseInt(long[2], 16), parseInt(long[3], 16)];
|
|
60
|
+
const short = color.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])(?:[0-9a-f])?$/i);
|
|
61
|
+
if (short) return [1, 2, 3].map((i) => parseInt(short[i] + short[i], 16));
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Split one box-shadow layer into top-level tokens.
|
|
67
|
+
*
|
|
68
|
+
* Whitespace inside parens does not separate tokens: `rgb(0 0 0)` and
|
|
69
|
+
* `var(--x, 4px)` are each a single value, and splitting them on spaces would
|
|
70
|
+
* read their innards as separate lengths.
|
|
71
|
+
*/
|
|
72
|
+
function tokenizeShadowLayer(layer) {
|
|
73
|
+
const tokens = [];
|
|
74
|
+
let depth = 0;
|
|
75
|
+
let current = '';
|
|
76
|
+
for (const char of String(layer || '')) {
|
|
77
|
+
if (char === '(') depth++;
|
|
78
|
+
else if (char === ')') depth--;
|
|
79
|
+
else if (depth === 0 && /\s/.test(char)) {
|
|
80
|
+
if (current) tokens.push(current);
|
|
81
|
+
current = '';
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
current += char;
|
|
56
85
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
if (current) tokens.push(current);
|
|
87
|
+
return tokens;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function lastMatch(text, re) {
|
|
91
|
+
const all = [...String(text || '').matchAll(re)];
|
|
92
|
+
return all.length ? all[all.length - 1] : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isShadowLength(token) {
|
|
96
|
+
return /^-?\d*\.?\d+(?:px)?$/i.test(String(token || ''));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Neutrality test for colors as written in source CSS.
|
|
101
|
+
*
|
|
102
|
+
* shared/color.mjs's isNeutralColor only parses the computed function forms a
|
|
103
|
+
* browser or jsdom emits (rgb/oklch/lab/...) and deliberately reports every
|
|
104
|
+
* other spelling as chromatic so an unknown format is never silently skipped.
|
|
105
|
+
* That default is wrong for authored CSS, where `#000` and `black` are the
|
|
106
|
+
* normal spellings: calling it directly reports a plain black hairline as a
|
|
107
|
+
* colored stripe. Handle hex and named neutrals here, then defer.
|
|
108
|
+
*/
|
|
109
|
+
function isNeutralAuthoredColor(rawColor) {
|
|
110
|
+
const c = String(rawColor || '').trim().toLowerCase();
|
|
111
|
+
if (!c) return false;
|
|
112
|
+
if (NEUTRAL_COLOR_KEYWORDS.has(c)) return true;
|
|
113
|
+
// Modern rgb() takes space-separated channels (`rgb(0 0 0)`). shared/color.mjs
|
|
114
|
+
// parses only the comma form a browser's getComputedStyle emits, so authored
|
|
115
|
+
// space-separated neutrals fell through it and reported as chromatic — the
|
|
116
|
+
// exemption this function exists for, missed. Normalize before delegating.
|
|
117
|
+
if (/^rgba?\(/i.test(c)) {
|
|
118
|
+
const channels = c.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);
|
|
119
|
+
if (channels) {
|
|
120
|
+
const values = [1, 2, 3].map((i) => Number(channels[i]));
|
|
121
|
+
return (Math.max(...values) - Math.min(...values)) < 30;
|
|
122
|
+
}
|
|
123
|
+
return isNeutralColor(c);
|
|
61
124
|
}
|
|
125
|
+
if (/^(?:hsla?|oklch|oklab|lab|lch|hwb)\(/i.test(c)) return isNeutralColor(c);
|
|
126
|
+
const channels = hexChannels(c);
|
|
127
|
+
if (channels) return (Math.max(...channels) - Math.min(...channels)) < 30;
|
|
62
128
|
return false;
|
|
63
129
|
}
|
|
64
130
|
|
|
131
|
+
function isNeutralBorderColor(str) {
|
|
132
|
+
const m = str.match(/solid\s+((?:rgba?|hsla?|oklch|oklab|lab|lch|hwb|color)\([^)]*\)|#[0-9a-f]{3,8}\b|[a-z]+)/i);
|
|
133
|
+
if (!m) return false;
|
|
134
|
+
return isNeutralAuthoredColor(m[1]);
|
|
135
|
+
}
|
|
136
|
+
|
|
65
137
|
const REGEX_MATCHERS = [
|
|
66
138
|
// --- Side-tab ---
|
|
67
139
|
{ id: 'side-tab', regex: /\bborder-[lrse]-(\d+)\b/g,
|
|
@@ -235,15 +307,34 @@ const REGEX_ANALYZERS = [
|
|
|
235
307
|
const dominant = Object.entries(counts).sort((a, b) => b[1] - a[1])[0][0];
|
|
236
308
|
return [finding('monotonous-spacing', filePath, `~${dominant}px used ${maxCount}/${rounded.length} times (${Math.round(pct * 100)}%)`)];
|
|
237
309
|
},
|
|
238
|
-
// Em-dash overuse:
|
|
239
|
-
//
|
|
240
|
-
//
|
|
310
|
+
// Em-dash overuse (ADVISORY): the AI cadence tell is em-dash *saturation*,
|
|
311
|
+
// not the occasional dash. Humans use em-dashes legitimately, so this rule is
|
|
312
|
+
// advisory (surfaced separately, never a failure, hook-skipped by default) and
|
|
313
|
+
// its threshold is deliberately conservative. Two gates must both hold:
|
|
314
|
+
// 1. Absolute floor of EM_DASH_FLOOR (8) dashes — a page with a handful
|
|
315
|
+
// never fires, no matter how short.
|
|
316
|
+
// 2. Density: at least one dash per EM_DASH_CHARS_PER_DASH (500) characters
|
|
317
|
+
// of body text, so a long article that uses eight across several thousand
|
|
318
|
+
// words is left alone while a short, dash-per-clause landing page is not.
|
|
319
|
+
// Raised from the old flat 5-dash floor, which fired on ordinary long prose.
|
|
320
|
+
//
|
|
321
|
+
// stripHtmlToText drops tags but leaves character-entity escapes intact, so
|
|
322
|
+
// a model that writes `—`, `—`, or `—` renders an em-dash
|
|
323
|
+
// the counter never saw. Decode the em-dash entities (named, zero-padded
|
|
324
|
+
// decimal, upper/lower hex) to the literal glyph first. En-dash entities are
|
|
325
|
+
// deliberately left alone: the rule counts em-dashes, and the literal `–`
|
|
326
|
+
// was never counted either.
|
|
241
327
|
(content, filePath) => {
|
|
242
|
-
const text = stripHtmlToText(content)
|
|
328
|
+
const text = stripHtmlToText(content)
|
|
329
|
+
.replace(/—|�*8212;|�*2014;/gi, '—');
|
|
243
330
|
let count = 0;
|
|
244
331
|
const re = /[—]|--(?=\S)/g;
|
|
245
332
|
while (re.exec(text) !== null) count++;
|
|
246
|
-
if (count <
|
|
333
|
+
if (count < EM_DASH_FLOOR) return [];
|
|
334
|
+
// Saturation gate: dashes must be dense in the prose, not sprinkled through
|
|
335
|
+
// a long document. textLength <= count * chars-per-dash means the density is
|
|
336
|
+
// at or above the threshold.
|
|
337
|
+
if (text.length > count * EM_DASH_CHARS_PER_DASH) return [];
|
|
247
338
|
return [finding('em-dash-overuse', filePath, `${count} em-dashes in body text`)];
|
|
248
339
|
},
|
|
249
340
|
// Marketing buzzwords: SaaS phrase list
|
|
@@ -279,22 +370,6 @@ const REGEX_ANALYZERS = [
|
|
|
279
370
|
if (count === 0) return [];
|
|
280
371
|
return [finding('marketing-buzzword', filePath, `${count} buzzword phrase${count === 1 ? '' : 's'}: "${firstSample}"`)];
|
|
281
372
|
},
|
|
282
|
-
// Numbered section markers (01 / 02 / 03 ...)
|
|
283
|
-
(content, filePath) => {
|
|
284
|
-
const text = stripHtmlToText(content);
|
|
285
|
-
const re = /\b(0[1-9]|1[0-2])\b/g;
|
|
286
|
-
const seen = new Set();
|
|
287
|
-
let m;
|
|
288
|
-
while ((m = re.exec(text)) !== null) seen.add(m[1]);
|
|
289
|
-
if (seen.size < 3) return [];
|
|
290
|
-
const sorted = [...seen].sort();
|
|
291
|
-
let sequential = 0;
|
|
292
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
293
|
-
if (parseInt(sorted[i], 10) === parseInt(sorted[i - 1], 10) + 1) sequential++;
|
|
294
|
-
}
|
|
295
|
-
if (sequential < 2) return [];
|
|
296
|
-
return [finding('numbered-section-markers', filePath, `Sequence: ${sorted.slice(0, 6).join(', ')}`)];
|
|
297
|
-
},
|
|
298
373
|
// Aphoristic cadence: manufactured-contrast + short-rebuttal
|
|
299
374
|
(content, filePath) => {
|
|
300
375
|
const text = stripHtmlToText(content);
|
|
@@ -316,41 +391,143 @@ const REGEX_ANALYZERS = [
|
|
|
316
391
|
if (count < 3) return [];
|
|
317
392
|
return [finding('aphoristic-cadence', filePath, `${count} aphoristic constructions: "${firstSample}"`)];
|
|
318
393
|
},
|
|
319
|
-
// Dark glow (page-level
|
|
394
|
+
// Dark glow / chromatic halo shadows (page-level). Shared scanner handles
|
|
395
|
+
// any color format, single-level var() resolution, zero-offset halos on
|
|
396
|
+
// any background, and text-shadow glows.
|
|
320
397
|
(content, filePath) => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
if (!hasDarkBg) return [];
|
|
326
|
-
|
|
327
|
-
// Check for colored box-shadow with blur > 4px
|
|
328
|
-
const shadowRe = /box-shadow\s*:\s*([^;{}]+)/gi;
|
|
329
|
-
let m;
|
|
330
|
-
while ((m = shadowRe.exec(content)) !== null) {
|
|
331
|
-
const val = m[1];
|
|
332
|
-
const colorMatch = val.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
333
|
-
if (!colorMatch) continue;
|
|
334
|
-
const [r, g, b] = [+colorMatch[1], +colorMatch[2], +colorMatch[3]];
|
|
335
|
-
if ((Math.max(r, g, b) - Math.min(r, g, b)) < 30) continue; // skip gray
|
|
336
|
-
// Check blur: look for pattern like "0 0 20px" (third number > 4)
|
|
337
|
-
const pxVals = [...val.matchAll(/(\d+)px|(?<![.\d])\b(0)\b(?![.\d])/g)].map(p => +(p[1] || p[2]));
|
|
338
|
-
if (pxVals.length >= 3 && pxVals[2] > 4) {
|
|
339
|
-
const lines = content.substring(0, m.index).split('\n');
|
|
340
|
-
return [finding('dark-glow', filePath, `Colored glow (rgb(${r},${g},${b})) on dark page`, lines.length)];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return [];
|
|
398
|
+
const hits = scanCssTextForGlow(content);
|
|
399
|
+
if (hits.length === 0) return [];
|
|
400
|
+
const lines = content.substring(0, hits[0].index).split('\n');
|
|
401
|
+
return [finding('dark-glow', filePath, hits[0].snippet, lines.length)];
|
|
344
402
|
},
|
|
403
|
+
// Radial-gradient background halo on a dark page (the gradient sibling
|
|
404
|
+
// of the dark-glow shadow tell).
|
|
405
|
+
(content, filePath) => {
|
|
406
|
+
const hits = scanCssTextForRadialHalo(content);
|
|
407
|
+
if (hits.length === 0) return [];
|
|
408
|
+
const lines = content.substring(0, hits[0].index).split('\n');
|
|
409
|
+
return [finding('radial-halo', filePath, hits[0].snippet, lines.length)];
|
|
410
|
+
},
|
|
411
|
+
// Auto-scrolling marquees (<marquee> or infinite horizontal loop
|
|
412
|
+
// animations).
|
|
413
|
+
(content, filePath) => scanCssTextForMarquee(content).map(hit => finding('marquee', filePath, hit.snippet)),
|
|
345
414
|
];
|
|
346
415
|
|
|
347
416
|
// ---------------------------------------------------------------------------
|
|
348
|
-
//
|
|
417
|
+
// Structural CSS checks used by source files whose styles are not parsed by
|
|
418
|
+
// the static HTML engine.
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
|
|
421
|
+
const CHROMATIC_SHADOW_TOKEN_RE = /(?:^|-)(?:accent|kinpaku|patina|gold|red|orange|amber|yellow|lime|green|emerald|teal|cyan|blue|indigo|violet|purple|magenta|pink|rose|coral|aqua|mint|burgundy|crimson|scarlet)(?:-|$)/i;
|
|
422
|
+
|
|
423
|
+
function insetStripeColorIsChromatic(rawColor) {
|
|
424
|
+
const color = String(rawColor || '').trim().replace(/\s*!important\s*$/i, '');
|
|
425
|
+
if (/^(?:currentcolor|transparent|inherit|unset)$/i.test(color)) return false;
|
|
426
|
+
const variable = color.match(/^var\(\s*(--[\w-]+)/i);
|
|
427
|
+
if (variable) return CHROMATIC_SHADOW_TOKEN_RE.test(variable[1]);
|
|
428
|
+
if (!/^(?:#|rgba?\(|hsla?\(|hwb\(|oklch\(|oklab\(|lch\(|lab\(|color\(|[a-z]+$)/i.test(color)) return false;
|
|
429
|
+
return !isNeutralAuthoredColor(color);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Blank out comment bodies while preserving every byte offset (and therefore
|
|
434
|
+
* every line number) so commented-out CSS is not scanned as live rules.
|
|
435
|
+
*/
|
|
436
|
+
function blankCssComments(css) {
|
|
437
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, (block) => block.replace(/[^\n]/g, ' '));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function scanInsetStripeCss(rawContent, filePath, lineOffset = 0) {
|
|
441
|
+
const content = blankCssComments(rawContent);
|
|
442
|
+
const findings = [];
|
|
443
|
+
const ruleRe = /([^{};]+)\{([^{}]*)\}/g;
|
|
444
|
+
let match;
|
|
445
|
+
// Deriving each line with content.slice(0, offset).split('\n') re-scans the
|
|
446
|
+
// whole prefix per rule, which is O(n^2) on a large stylesheet. Rule matches
|
|
447
|
+
// arrive in source order, so carry a monotonic cursor instead: one pass total.
|
|
448
|
+
let scanOffset = 0;
|
|
449
|
+
let scanLine = 1;
|
|
450
|
+
const lineAtOffset = (offset) => {
|
|
451
|
+
while (scanOffset < offset) {
|
|
452
|
+
if (content[scanOffset] === '\n') scanLine++;
|
|
453
|
+
scanOffset++;
|
|
454
|
+
}
|
|
455
|
+
return scanLine;
|
|
456
|
+
};
|
|
457
|
+
while ((match = ruleRe.exec(content)) !== null) {
|
|
458
|
+
// The selector group is `[^{};]+`, which greedily absorbs the whitespace and
|
|
459
|
+
// newlines trailing the previous rule. Advance past that run before deriving
|
|
460
|
+
// the line, or every rule after the first reports the preceding line.
|
|
461
|
+
const selectorStart = match.index + (match[1].length - match[1].trimStart().length);
|
|
462
|
+
const selector = match[1].trim().replace(/\s+/g, ' ');
|
|
463
|
+
if (!selector) continue;
|
|
464
|
+
if (/:(?:hover|focus|focus-visible|focus-within|active|checked|target)\b/i.test(selector)) continue;
|
|
465
|
+
if (/\[aria-selected\s*[*^$|~]?=\s*["']?true/i.test(selector)) continue;
|
|
466
|
+
if (/\[aria-current(?!\s*[*^$|~]?=\s*["']?false)/i.test(selector)) continue;
|
|
467
|
+
if (/(?:^|[\s._[-])(?:active|current|selected)(?![\w])/i.test(selector)) continue;
|
|
468
|
+
if (/(?:^|[\s>+~,(])(?:button|hr|tr|td|th|table|blockquote|pre|code)(?![\w-])/i.test(selector)) continue;
|
|
469
|
+
|
|
470
|
+
// Read the last of a repeated declaration, not the first: that is what the
|
|
471
|
+
// cascade paints. Taking the first both flagged stripes that a later
|
|
472
|
+
// `box-shadow: none` had cancelled and missed stripes that overrode an
|
|
473
|
+
// earlier value, and mis-skipped rules whose narrow width was overridden.
|
|
474
|
+
const width = lastMatch(match[2], /(?:^|;)\s*(?:width|inline-size)\s*:\s*(\d+(?:\.\d+)?)px/gi);
|
|
475
|
+
if (width && Number(width[1]) <= 40) continue;
|
|
476
|
+
const declaration = lastMatch(match[2], /(?:^|;)\s*box-shadow\s*:\s*([^;]+)/gi);
|
|
477
|
+
if (!declaration || !/\binset\b/i.test(declaration[1])) continue;
|
|
478
|
+
// `!important` qualifies the declaration, not the shadow value, so strip it
|
|
479
|
+
// before the layers are read. Tokenizing split it into its own token, which
|
|
480
|
+
// made the color count wrong and silently stopped flagging stripes declared
|
|
481
|
+
// with it — a shape the previous regex handled.
|
|
482
|
+
const shadowValue = declaration[1].replace(/\s*!\s*important\s*$/i, '').trim();
|
|
483
|
+
|
|
484
|
+
for (const rawLayer of shadowValue.split(/,(?![^(]*\))/)) {
|
|
485
|
+
const layer = rawLayer.trim();
|
|
486
|
+
// Parse the layer by its grammar rather than by one spelling of it.
|
|
487
|
+
// A box-shadow layer is `inset? && <length>{2,4} && <color>?` in any
|
|
488
|
+
// order, so `inset 4px 0 red`, `4px 0 0 red inset`, and `red 4px 0 inset`
|
|
489
|
+
// all paint the same stripe. Matching a fixed token order missed three
|
|
490
|
+
// valid spellings in a row; enumerate the tokens instead. Tokenizing must
|
|
491
|
+
// respect parens: `rgb(0 0 0)` is one color token, and splitting it on
|
|
492
|
+
// whitespace would read its channels as lengths.
|
|
493
|
+
const tokens = tokenizeShadowLayer(layer);
|
|
494
|
+
if (!tokens.some((token) => /^inset$/i.test(token))) continue;
|
|
495
|
+
const rest = tokens.filter((token) => !/^inset$/i.test(token));
|
|
496
|
+
const lengths = rest.filter(isShadowLength);
|
|
497
|
+
const colors = rest.filter((token) => !isShadowLength(token));
|
|
498
|
+
// Only the two offsets are required; omitted blur/spread default to 0,
|
|
499
|
+
// which is exactly the stripe shape. More than one non-length token is a
|
|
500
|
+
// layer shape we do not claim to understand, so leave it alone.
|
|
501
|
+
if (lengths.length < 2 || lengths.length > 4 || colors.length !== 1) continue;
|
|
502
|
+
const values = lengths.map((token) => ({
|
|
503
|
+
n: Number(token.replace(/px$/i, '')),
|
|
504
|
+
hasPx: /px$/i.test(token),
|
|
505
|
+
}));
|
|
506
|
+
const x = values[0];
|
|
507
|
+
const y = values[1];
|
|
508
|
+
const blur = values[2] ? values[2].n : 0;
|
|
509
|
+
const spread = values[3] ? values[3].n : 0;
|
|
510
|
+
if ((x.n !== 0 && !x.hasPx) || (y.n !== 0 && !y.hasPx) || blur !== 0 || spread !== 0) continue;
|
|
511
|
+
const ax = Math.abs(x.n);
|
|
512
|
+
const ay = Math.abs(y.n);
|
|
513
|
+
if (!((ax >= 3 && ax <= 12 && ay === 0) || (ay >= 3 && ay <= 12 && ax === 0))) continue;
|
|
514
|
+
if (!insetStripeColorIsChromatic(colors[0])) continue;
|
|
515
|
+
const edge = ay === 0 ? (x.n > 0 ? 'left' : 'right') : (y.n > 0 ? 'top' : 'bottom');
|
|
516
|
+
const line = lineOffset + lineAtOffset(selectorStart);
|
|
517
|
+
findings.push(finding('side-tab', filePath, `${selector} — inset box-shadow ${ay === 0 ? ax : ay}px stripe (${edge})`, line));
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return findings;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// ---------------------------------------------------------------------------
|
|
525
|
+
// Style block extraction (Astro/Vue/Svelte <style> blocks)
|
|
349
526
|
// ---------------------------------------------------------------------------
|
|
350
527
|
|
|
351
528
|
function extractStyleBlocks(content, ext) {
|
|
352
529
|
ext = ext.toLowerCase();
|
|
353
|
-
if (ext !== '.vue' && ext !== '.svelte') return [];
|
|
530
|
+
if (ext !== '.astro' && ext !== '.vue' && ext !== '.svelte') return [];
|
|
354
531
|
const blocks = [];
|
|
355
532
|
const re = /<style[^>]*>([\s\S]*?)<\/style>/gi;
|
|
356
533
|
let m;
|
|
@@ -435,21 +612,20 @@ function runRegexMatchers(lines, filePath, lineOffset = 0, blockContext = null,
|
|
|
435
612
|
}
|
|
436
613
|
|
|
437
614
|
/** Page-level analyzers that scan rendered text content (em-dash use,
|
|
438
|
-
* buzzword phrases,
|
|
615
|
+
* buzzword phrases, aphoristic cadence).
|
|
439
616
|
* These are detector-agnostic — they work on any HTML/text source
|
|
440
617
|
* and don't need a parsed DOM. Exported so detectHtml can call them
|
|
441
618
|
* for `.html` files (which otherwise skip the regex engine). */
|
|
442
619
|
const TEXT_CONTENT_ANALYZER_IDS = [
|
|
443
620
|
'em-dash-overuse',
|
|
444
621
|
'marketing-buzzword',
|
|
445
|
-
'numbered-section-markers',
|
|
446
622
|
'aphoristic-cadence',
|
|
447
623
|
];
|
|
448
624
|
|
|
449
625
|
function runTextContentAnalyzers(content, filePath, options = {}) {
|
|
450
626
|
const profile = options?.profile;
|
|
451
627
|
if (!shouldRunPageAnalyzers(content, filePath)) return [];
|
|
452
|
-
// The
|
|
628
|
+
// The 3 text-content analyzers are at indices 3-5 in REGEX_ANALYZERS.
|
|
453
629
|
const findings = [];
|
|
454
630
|
for (let i = 0; i < TEXT_CONTENT_ANALYZER_IDS.length; i++) {
|
|
455
631
|
const analyzer = REGEX_ANALYZERS[3 + i];
|
|
@@ -477,8 +653,22 @@ function detectText(content, filePath, options = {}) {
|
|
|
477
653
|
profile,
|
|
478
654
|
phase: 'source',
|
|
479
655
|
}));
|
|
656
|
+
if (cssLike.has(ext)) findings.push(...scanInsetStripeCss(content, filePath));
|
|
657
|
+
|
|
658
|
+
// Block-level CSS checks that need multiple declarations must run over the
|
|
659
|
+
// complete source, not line-by-line. This covers standalone stylesheets,
|
|
660
|
+
// component style blocks, inline styles, and CSS-in-JS templates.
|
|
661
|
+
findings.push(...profileFindings(profile, {
|
|
662
|
+
engine: 'regex',
|
|
663
|
+
phase: 'source',
|
|
664
|
+
ruleId: 'codex-grid-background',
|
|
665
|
+
target: filePath,
|
|
666
|
+
}, () => scanCssTextForGridBackground(content).map(hit => {
|
|
667
|
+
const line = content.substring(0, hit.index).split('\n').length;
|
|
668
|
+
return finding('codex-grid-background', filePath, hit.snippet, line);
|
|
669
|
+
})));
|
|
480
670
|
|
|
481
|
-
// Extract and scan <style> blocks from Vue/Svelte
|
|
671
|
+
// Extract and scan <style> blocks from Astro/Vue/Svelte components.
|
|
482
672
|
const styleBlocks = profile
|
|
483
673
|
? profileStep(profile, {
|
|
484
674
|
engine: 'regex',
|
|
@@ -493,6 +683,13 @@ function detectText(content, filePath, options = {}) {
|
|
|
493
683
|
profile,
|
|
494
684
|
phase: 'style-block',
|
|
495
685
|
}));
|
|
686
|
+
// block.startLine is the first line *after* the <style> tag, but block.content
|
|
687
|
+
// begins at the character right after that tag — so its own line 1 sits on the
|
|
688
|
+
// tag's line, whether or not a newline follows immediately. lineAtOffset is
|
|
689
|
+
// 1-based, so the offset is startLine - 2; startLine - 1 double-counted and
|
|
690
|
+
// reported every selector one line low. runRegexMatchers keeps startLine - 1
|
|
691
|
+
// because it indexes its split lines from zero.
|
|
692
|
+
findings.push(...scanInsetStripeCss(block.content, filePath, block.startLine - 2));
|
|
496
693
|
}
|
|
497
694
|
|
|
498
695
|
// Extract and scan CSS-in-JS template literals
|
|
@@ -510,6 +707,7 @@ function detectText(content, filePath, options = {}) {
|
|
|
510
707
|
profile,
|
|
511
708
|
phase: 'css-in-js',
|
|
512
709
|
}));
|
|
710
|
+
findings.push(...scanInsetStripeCss(block.content, filePath, block.startLine - 1));
|
|
513
711
|
}
|
|
514
712
|
|
|
515
713
|
if (options?.designSystem) {
|
|
@@ -540,7 +738,6 @@ function detectText(content, filePath, options = {}) {
|
|
|
540
738
|
'monotonous-spacing',
|
|
541
739
|
'em-dash-overuse',
|
|
542
740
|
'marketing-buzzword',
|
|
543
|
-
'numbered-section-markers',
|
|
544
741
|
'aphoristic-cadence',
|
|
545
742
|
'dark-glow',
|
|
546
743
|
];
|
|
@@ -555,10 +752,9 @@ function detectText(content, filePath, options = {}) {
|
|
|
555
752
|
}
|
|
556
753
|
}
|
|
557
754
|
|
|
558
|
-
const byProvider = filterByProviders(deduped, options?.providers);
|
|
559
755
|
// Inline `impeccable-disable*` waivers travel with the file; honor them unless
|
|
560
756
|
// explicitly bypassed (`--no-config` / `--no-inline-ignores`).
|
|
561
|
-
return options?.inlineIgnores === false ?
|
|
757
|
+
return options?.inlineIgnores === false ? deduped : applyInlineIgnores(deduped, content);
|
|
562
758
|
}
|
|
563
759
|
|
|
564
760
|
export {
|