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
|
@@ -1222,7 +1222,11 @@ if (IS_BROWSER) {
|
|
|
1222
1222
|
return {
|
|
1223
1223
|
type: f.type || f.id,
|
|
1224
1224
|
category: ap ? ap.category : 'quality',
|
|
1225
|
-
severity: ap?.severity || 'warning',
|
|
1225
|
+
severity: f.severity || ap?.severity || 'warning',
|
|
1226
|
+
// Advisory findings (em-dash overuse, etc.) are surfaced but never
|
|
1227
|
+
// treated as failures; carry the flag so the overlay/extension can
|
|
1228
|
+
// render them with the mildest affordance and consumers can filter.
|
|
1229
|
+
advisory: (ap && ap.advisory === true) || f.advisory === true,
|
|
1226
1230
|
detail: f.detail || f.snippet,
|
|
1227
1231
|
ignoreValue: f.ignoreValue || f.value || '',
|
|
1228
1232
|
name: ap ? ap.name : (f.type || f.id),
|
|
@@ -1458,10 +1462,7 @@ if (IS_BROWSER) {
|
|
|
1458
1462
|
const _ruleOk = (id) => !_disabled.length || !_disabled.includes(id);
|
|
1459
1463
|
const designSystem = browserDesignSystemConfig();
|
|
1460
1464
|
const designSeen = { fonts: new Set(), colors: new Set(), radii: new Set() };
|
|
1461
|
-
//
|
|
1462
|
-
// real browser env (detector page, live overlay, extension) running every
|
|
1463
|
-
// check is free, so we always surface them; the gating is purely a CLI
|
|
1464
|
-
// output concern, applied in the Node engines' detect* return paths.
|
|
1465
|
+
// All deterministic rules run in the browser and extension path.
|
|
1465
1466
|
|
|
1466
1467
|
for (const el of document.querySelectorAll('*')) {
|
|
1467
1468
|
// Skip impeccable's own elements and any descendants (overlays, labels, banner, nav buttons)
|
|
@@ -1477,6 +1478,7 @@ if (IS_BROWSER) {
|
|
|
1477
1478
|
|
|
1478
1479
|
const findings = [
|
|
1479
1480
|
...checkElementBordersDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1481
|
+
...checkElementPseudoStripeDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1480
1482
|
...checkElementColorsDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1481
1483
|
...checkElementMotionDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1482
1484
|
...checkElementGlowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
@@ -1488,6 +1490,7 @@ if (IS_BROWSER) {
|
|
|
1488
1490
|
...checkElementClippedOverflowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1489
1491
|
...checkElementGptBorderShadowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1490
1492
|
...checkElementTextOverflowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1493
|
+
...checkElementBlinkingCursorDOM(el).map(f => ({ type: f.id, detail: f.snippet, ...(f.severity ? { severity: f.severity } : {}) })),
|
|
1491
1494
|
...checkElementDesignSystemDOM(el, designSystem, designSeen),
|
|
1492
1495
|
].filter(f => _ruleOk(f.type));
|
|
1493
1496
|
|
|
@@ -1526,12 +1529,66 @@ if (IS_BROWSER) {
|
|
|
1526
1529
|
addBrowserFindings(groupMap, document.body, sectionKickerFindings);
|
|
1527
1530
|
}
|
|
1528
1531
|
|
|
1532
|
+
const numberedLabelFindings = checkNumberedSectionLabelsDOM()
|
|
1533
|
+
.map(f => ({ type: f.id, detail: f.snippet }))
|
|
1534
|
+
.filter(f => _ruleOk(f.type));
|
|
1535
|
+
if (numberedLabelFindings.length > 0) {
|
|
1536
|
+
pageLevelFindings.push(...numberedLabelFindings);
|
|
1537
|
+
addBrowserFindings(groupMap, document.body, numberedLabelFindings);
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
const repeatedTextFindings = checkRepeatedContainerTextDOM()
|
|
1541
|
+
.map(f => ({ type: f.id, detail: f.snippet }))
|
|
1542
|
+
.filter(f => _ruleOk(f.type));
|
|
1543
|
+
if (repeatedTextFindings.length > 0) {
|
|
1544
|
+
pageLevelFindings.push(...repeatedTextFindings);
|
|
1545
|
+
addBrowserFindings(groupMap, document.body, repeatedTextFindings);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// Em-dash overuse (advisory): browser parity with the static/regex path.
|
|
1549
|
+
// Reads rendered body text so it catches dashes written as HTML entities.
|
|
1550
|
+
// serializeFindings stamps the advisory flag from the registry.
|
|
1551
|
+
const emDashFindings = checkEmDashOveruseDOM()
|
|
1552
|
+
.map(f => ({ type: f.id, detail: f.snippet }))
|
|
1553
|
+
.filter(f => _ruleOk(f.type));
|
|
1554
|
+
if (emDashFindings.length > 0) {
|
|
1555
|
+
pageLevelFindings.push(...emDashFindings);
|
|
1556
|
+
addBrowserFindings(groupMap, document.body, emDashFindings);
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1529
1559
|
const layoutFindings = checkLayout().filter(f => _ruleOk(f.type));
|
|
1530
1560
|
for (const f of layoutFindings) {
|
|
1531
1561
|
const el = f.el || document.body;
|
|
1532
1562
|
addBrowserFindings(groupMap, el, [{ type: f.type, detail: f.detail || f.snippet }]);
|
|
1533
1563
|
}
|
|
1534
1564
|
|
|
1565
|
+
// Heading rhythm (browser-only: needs real layout for the gap math)
|
|
1566
|
+
const headingRhythmFindings = checkHeadingRhythmDOM().filter(f => _ruleOk(f.type));
|
|
1567
|
+
for (const f of headingRhythmFindings) {
|
|
1568
|
+
addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
// Edge-flush cards in horizontal scrollers (browser-only: needs real
|
|
1572
|
+
// layout for the scroller clip box vs card rect math)
|
|
1573
|
+
const edgeFlushFindings = checkEdgeFlushCardsDOM().filter(f => _ruleOk(f.type));
|
|
1574
|
+
for (const f of edgeFlushFindings) {
|
|
1575
|
+
addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// Text occlusion / element overlap (browser-only: needs real layout +
|
|
1579
|
+
// elementFromPoint to confirm what actually paints on top)
|
|
1580
|
+
const occlusionFindings = checkTextOcclusionDOM().filter(f => _ruleOk(f.type));
|
|
1581
|
+
for (const f of occlusionFindings) {
|
|
1582
|
+
addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// First-viewport column overflow — the stretched-hero signature
|
|
1586
|
+
// (browser-only: needs real layout for the content-extent math)
|
|
1587
|
+
const colOverflowFindings = checkFirstViewportColumnOverflowDOM().filter(f => _ruleOk(f.type));
|
|
1588
|
+
for (const f of colOverflowFindings) {
|
|
1589
|
+
addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1535
1592
|
// Page-level quality checks (headings, etc.)
|
|
1536
1593
|
const qualityFindings = checkPageQualityDOM().filter(f => _ruleOk(f.type));
|
|
1537
1594
|
if (qualityFindings.length > 0) {
|
|
@@ -1557,7 +1614,25 @@ if (IS_BROWSER) {
|
|
|
1557
1614
|
}
|
|
1558
1615
|
const htmlPatternFindings = checkHtmlPatterns(docClone.outerHTML);
|
|
1559
1616
|
if (htmlPatternFindings.length > 0) {
|
|
1560
|
-
const mapped = htmlPatternFindings.map(f =>
|
|
1617
|
+
const mapped = htmlPatternFindings.map(f => {
|
|
1618
|
+
const item = { type: f.id, detail: f.snippet };
|
|
1619
|
+
if (f.severity) {
|
|
1620
|
+
item.severity = f.severity;
|
|
1621
|
+
} else if (f.id === 'pulsing-dot' && f.selector) {
|
|
1622
|
+
// The string scan promotes header/nav dots on its own; with a live
|
|
1623
|
+
// layout also promote dots resting in the first ~900px of the page
|
|
1624
|
+
// (the hero region), which the source scan cannot measure.
|
|
1625
|
+
try {
|
|
1626
|
+
const dotEl = document.querySelector(f.selector);
|
|
1627
|
+
if (dotEl) {
|
|
1628
|
+
const rect = dotEl.getBoundingClientRect();
|
|
1629
|
+
const pageTop = rect.top + (window.scrollY || 0);
|
|
1630
|
+
if (pageTop <= 900) item.severity = 'error';
|
|
1631
|
+
}
|
|
1632
|
+
} catch { /* unresolvable selector: keep registry severity */ }
|
|
1633
|
+
}
|
|
1634
|
+
return item;
|
|
1635
|
+
}).filter(f => _ruleOk(f.type));
|
|
1561
1636
|
pageLevelFindings.push(...mapped);
|
|
1562
1637
|
addBrowserFindings(groupMap, document.body, mapped);
|
|
1563
1638
|
}
|
|
@@ -1931,6 +2006,9 @@ if (IS_BROWSER) {
|
|
|
1931
2006
|
window.impeccableDetectAsync = detectAsync;
|
|
1932
2007
|
window.impeccableScan = scan;
|
|
1933
2008
|
window.impeccableScanAsync = scanAsync;
|
|
2009
|
+
// Raw measurement for the URL engine's content-hidden-at-rest pass: it
|
|
2010
|
+
// drives a reveal sweep from Node and thresholds the result itself.
|
|
2011
|
+
window.impeccableMeasureHiddenText = measureHiddenTextDOM;
|
|
1934
2012
|
window.impeccableCollectVisualContrastCandidates = collectVisualContrastCandidates;
|
|
1935
2013
|
window.impeccableAnalyzeVisualContrast = analyzeVisualContrast;
|
|
1936
2014
|
window.impeccableGetLastVisualContrastAnalyses = () => lastVisualContrastAnalyses.slice();
|
package/cli/engine/cli/main.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import { loadDesignSystemForTarget } from '../design-system.mjs';
|
|
5
6
|
import { RULE_SCOPES, filterByScopes } from '../registry/antipatterns.mjs';
|
|
6
7
|
import { createBrowserDetector, detectUrl } from '../engines/browser/detect-url.mjs';
|
|
7
8
|
import { detectHtml } from '../engines/static-html/detect-html.mjs';
|
|
@@ -27,9 +28,37 @@ function formatFindingSummary(count) {
|
|
|
27
28
|
return `${count} anti-pattern${count === 1 ? '' : 's'} found.`;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
// Local filesystem path behind a file:// URL, or null when it can't be mapped.
|
|
32
|
+
function fileUrlToLocalPath(url) {
|
|
33
|
+
try {
|
|
34
|
+
return fileURLToPath(url);
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Advisory findings are detected but never treated as failures: they list in a
|
|
41
|
+
// separate, visually dimmed section, are excluded from the failure count that
|
|
42
|
+
// drives the exit code, and carry `"advisory": true` in JSON so consumers can
|
|
43
|
+
// filter. Every advisory finding carries the flag (stamped by the registry via
|
|
44
|
+
// findings.mjs).
|
|
45
|
+
function isAdvisory(finding) {
|
|
46
|
+
return finding && finding.advisory === true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function partitionAdvisory(findings) {
|
|
50
|
+
const primary = [];
|
|
51
|
+
const advisory = [];
|
|
52
|
+
for (const f of findings) (isAdvisory(f) ? advisory : primary).push(f);
|
|
53
|
+
return { primary, advisory };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ANSI dim, when stderr is a TTY. Advisory output is chrome, so keep it quiet.
|
|
57
|
+
function dim(text) {
|
|
58
|
+
return process.stderr.isTTY ? `\x1b[2m${text}\x1b[0m` : text;
|
|
59
|
+
}
|
|
32
60
|
|
|
61
|
+
function formatFindingsBody(findings) {
|
|
33
62
|
const grouped = {};
|
|
34
63
|
for (const f of findings) {
|
|
35
64
|
if (!grouped[f.file]) grouped[f.file] = [];
|
|
@@ -44,7 +73,28 @@ function formatFindings(findings, jsonMode) {
|
|
|
44
73
|
out.push(` → ${item.description}`);
|
|
45
74
|
}
|
|
46
75
|
}
|
|
47
|
-
out
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function formatAdvisorySection(advisory) {
|
|
80
|
+
if (!advisory || advisory.length === 0) return '';
|
|
81
|
+
const lines = [`\n${dim('── Advisory (not counted as failures) ──')}`];
|
|
82
|
+
for (const line of formatFindingsBody(advisory)) lines.push(dim(line));
|
|
83
|
+
lines.push(dim(`\n${advisory.length} advisory note${advisory.length === 1 ? '' : 's'}. Suppress with --no-advisory.`));
|
|
84
|
+
return lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Text/JSON formatter. `findings` is the full set; advisory items are separated
|
|
88
|
+
// out into their own section and excluded from the failure summary count. JSON
|
|
89
|
+
// output keeps every finding (each advisory one flagged) in a single array.
|
|
90
|
+
function formatFindings(findings, jsonMode) {
|
|
91
|
+
if (jsonMode) return JSON.stringify(findings, null, 2);
|
|
92
|
+
|
|
93
|
+
const { primary, advisory } = partitionAdvisory(findings);
|
|
94
|
+
const out = [...formatFindingsBody(primary)];
|
|
95
|
+
out.push(`\n${formatFindingSummary(primary.length)}`);
|
|
96
|
+
const advisorySection = formatAdvisorySection(advisory);
|
|
97
|
+
if (advisorySection) out.push(advisorySection);
|
|
48
98
|
return out.join('\n');
|
|
49
99
|
}
|
|
50
100
|
|
|
@@ -52,7 +102,11 @@ function formatFindings(findings, jsonMode) {
|
|
|
52
102
|
// Stdin handling
|
|
53
103
|
// ---------------------------------------------------------------------------
|
|
54
104
|
|
|
55
|
-
|
|
105
|
+
// `optionsFor` maps a local path to scan options carrying that path's own
|
|
106
|
+
// project design system (or base options when null). Falls back to a plain
|
|
107
|
+
// object so direct/legacy callers still work.
|
|
108
|
+
async function handleStdin(optionsFor = () => ({})) {
|
|
109
|
+
const resolve = typeof optionsFor === 'function' ? optionsFor : () => optionsFor;
|
|
56
110
|
const chunks = [];
|
|
57
111
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
58
112
|
const input = Buffer.concat(chunks).toString('utf-8');
|
|
@@ -60,11 +114,12 @@ async function handleStdin(options = {}) {
|
|
|
60
114
|
const parsed = JSON.parse(input);
|
|
61
115
|
const fp = parsed?.tool_input?.file_path;
|
|
62
116
|
if (fp && fs.existsSync(fp)) {
|
|
117
|
+
const options = resolve(fp);
|
|
63
118
|
return HTML_EXTENSIONS.has(path.extname(fp).toLowerCase())
|
|
64
119
|
? detectHtml(fp, options) : detectText(fs.readFileSync(fp, 'utf-8'), fp, options);
|
|
65
120
|
}
|
|
66
121
|
} catch { /* not JSON */ }
|
|
67
|
-
return detectText(input, '<stdin>',
|
|
122
|
+
return detectText(input, '<stdin>', resolve(null));
|
|
68
123
|
}
|
|
69
124
|
|
|
70
125
|
|
|
@@ -92,16 +147,22 @@ Scan files or URLs for UI anti-patterns and design quality issues.
|
|
|
92
147
|
Options:
|
|
93
148
|
--json Output results as JSON
|
|
94
149
|
--quiet In text mode, only print the final findings count
|
|
95
|
-
--gpt Also report GPT-specific provider tells (off by default)
|
|
96
|
-
--gemini Also report Gemini-specific provider tells (off by default)
|
|
97
150
|
--scope <name> Only report rules in the given design domain
|
|
98
151
|
(type, layout). Comma-separated.
|
|
152
|
+
--viewport <WxH> Browser viewport for URL scans (default 1280x800),
|
|
153
|
+
e.g. --viewport 390x844 for a mobile-width pass
|
|
99
154
|
--no-config Do not apply project config, detector ignores, inline
|
|
100
155
|
ignore comments, or DESIGN.md
|
|
101
156
|
--no-inline-ignores Do not honor in-file impeccable-disable* ignore comments
|
|
102
157
|
--no-design-system Do not load local DESIGN.md / .impeccable/design.json context
|
|
158
|
+
--no-advisory Suppress advisory findings entirely (e.g. em-dash overuse)
|
|
103
159
|
--help Show this help message
|
|
104
160
|
|
|
161
|
+
Advisory findings:
|
|
162
|
+
Some rules are advisory: detected and listed in a separate section, but never
|
|
163
|
+
counted as failures and never changing the exit code. They stay out of the
|
|
164
|
+
failure count so they never block automation. --no-advisory hides them.
|
|
165
|
+
|
|
105
166
|
Project config:
|
|
106
167
|
Respects .impeccable/config.json and .impeccable/config.local.json detector
|
|
107
168
|
settings: detector.ignoreRules, detector.ignoreFiles, detector.ignoreValues,
|
|
@@ -118,7 +179,8 @@ Inline ignores:
|
|
|
118
179
|
Detection modes:
|
|
119
180
|
HTML files Static HTML/CSS analysis (default, catches linked CSS)
|
|
120
181
|
Non-HTML files Regex pattern matching (CSS, JSX, TSX, etc.)
|
|
121
|
-
URLs Puppeteer full browser rendering (auto-detected
|
|
182
|
+
URLs Puppeteer full browser rendering (auto-detected;
|
|
183
|
+
http(s):// and file:// URLs)
|
|
122
184
|
|
|
123
185
|
Examples:
|
|
124
186
|
impeccable detect src/
|
|
@@ -138,6 +200,7 @@ async function detectCli() {
|
|
|
138
200
|
const jsonMode = args.includes('--json');
|
|
139
201
|
const quietMode = args.includes('--quiet');
|
|
140
202
|
const helpMode = args.includes('--help');
|
|
203
|
+
const noAdvisory = args.includes('--no-advisory');
|
|
141
204
|
// --fast (regex-only) is deprecated: since the jsdom removal, the static
|
|
142
205
|
// HTML/CSS analysis is fast and covers every rule, so the regex-only path
|
|
143
206
|
// only loses coverage for no real speed win. Accept the flag for back-compat
|
|
@@ -147,13 +210,15 @@ async function detectCli() {
|
|
|
147
210
|
'Note: --fast is deprecated and ignored. The full scan is fast now and runs every rule.\n',
|
|
148
211
|
);
|
|
149
212
|
}
|
|
213
|
+
if (args.includes('--gpt') || args.includes('--gemini')) {
|
|
214
|
+
process.stderr.write(
|
|
215
|
+
'Note: --gpt and --gemini are deprecated and ignored. Generated-UI tells now run by default.\n',
|
|
216
|
+
);
|
|
217
|
+
}
|
|
150
218
|
const configEnabled = !args.includes('--no-config');
|
|
151
219
|
const detectionConfig = configEnabled
|
|
152
220
|
? readDetectionConfig(process.cwd())
|
|
153
221
|
: { ignoreRules: [], ignoreFiles: [], ignoreValues: [] };
|
|
154
|
-
const providers = [];
|
|
155
|
-
if (args.includes('--gpt')) providers.push('gpt');
|
|
156
|
-
if (args.includes('--gemini')) providers.push('gemini');
|
|
157
222
|
const scopes = [];
|
|
158
223
|
for (let i = 0; i < args.length; i++) {
|
|
159
224
|
if (args[i] !== '--scope' && !args[i].startsWith('--scope=')) continue;
|
|
@@ -174,6 +239,20 @@ async function detectCli() {
|
|
|
174
239
|
args.splice(i, inline ? 1 : 2);
|
|
175
240
|
i -= 1;
|
|
176
241
|
}
|
|
242
|
+
let viewport = null;
|
|
243
|
+
for (let i = 0; i < args.length; i++) {
|
|
244
|
+
if (args[i] !== '--viewport' && !args[i].startsWith('--viewport=')) continue;
|
|
245
|
+
const inline = args[i].startsWith('--viewport=');
|
|
246
|
+
const value = inline ? args[i].slice('--viewport='.length) : args[i + 1];
|
|
247
|
+
const match = /^(\d{2,5})x(\d{2,5})$/i.exec(value || '');
|
|
248
|
+
if (!match) {
|
|
249
|
+
process.stderr.write('Error: --viewport requires a WxH value, e.g. --viewport 390x844\n');
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
viewport = { width: Number(match[1]), height: Number(match[2]) };
|
|
253
|
+
args.splice(i, inline ? 1 : 2);
|
|
254
|
+
i -= 1;
|
|
255
|
+
}
|
|
177
256
|
const unknownScopes = scopes.filter(s => !RULE_SCOPES.has(s));
|
|
178
257
|
if (unknownScopes.length > 0) {
|
|
179
258
|
process.stderr.write(
|
|
@@ -182,13 +261,23 @@ async function detectCli() {
|
|
|
182
261
|
process.exit(1);
|
|
183
262
|
}
|
|
184
263
|
const designSystemEnabled = configEnabled && !args.includes('--no-design-system') && detectionConfig.designSystem?.enabled !== false;
|
|
185
|
-
const designSystem = designSystemEnabled ? loadDesignSystemForCwd(process.cwd()) : null;
|
|
186
264
|
// Inline `impeccable-disable*` waivers are part of the scanned file, so they
|
|
187
265
|
// apply by default. `--no-config` (raw scan) and the dedicated
|
|
188
266
|
// `--no-inline-ignores` both turn them off.
|
|
189
267
|
const inlineIgnoresEnabled = configEnabled && !args.includes('--no-inline-ignores');
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
268
|
+
const baseScanOptions = { inlineIgnores: inlineIgnoresEnabled };
|
|
269
|
+
if (viewport) baseScanOptions.viewport = viewport;
|
|
270
|
+
// DESIGN.md must resolve from EACH scan target's own project root, not from
|
|
271
|
+
// process.cwd(): scanning project B's files from inside project A applied A's
|
|
272
|
+
// design rules (cross-project contamination). Resolve per target, memoized by
|
|
273
|
+
// resolved project root so a multi-file scan pays the read once per project.
|
|
274
|
+
// A target with no project marker above it gets no design system (never cwd's).
|
|
275
|
+
const designSystemCache = new Map();
|
|
276
|
+
const scanOptionsFor = (localPath) => {
|
|
277
|
+
if (!designSystemEnabled || !localPath) return baseScanOptions;
|
|
278
|
+
const designSystem = loadDesignSystemForTarget(localPath, { cache: designSystemCache });
|
|
279
|
+
return designSystem ? { ...baseScanOptions, designSystem } : baseScanOptions;
|
|
280
|
+
};
|
|
192
281
|
const targets = args.filter(a => !a.startsWith('--'));
|
|
193
282
|
|
|
194
283
|
if (helpMode) { printUsage(); process.exit(0); }
|
|
@@ -196,19 +285,31 @@ async function detectCli() {
|
|
|
196
285
|
let allFindings = [];
|
|
197
286
|
|
|
198
287
|
if (!process.stdin.isTTY && targets.length === 0) {
|
|
199
|
-
allFindings = await handleStdin(
|
|
288
|
+
allFindings = await handleStdin(scanOptionsFor);
|
|
200
289
|
} else {
|
|
201
290
|
const paths = targets.length > 0 ? targets : [process.cwd()];
|
|
202
|
-
|
|
291
|
+
// file:// URLs get the same Puppeteer-rendered pass as http(s) — the
|
|
292
|
+
// real cascade, real computed styles, real layout. Callers that want a
|
|
293
|
+
// browser-grade scan of a local artifact can pass file:///abs/path.html
|
|
294
|
+
// instead of the bare path (which stays on the static engine).
|
|
295
|
+
const urlRe = /^(?:https?|file):\/\//i;
|
|
296
|
+
const urlTargetCount = paths.filter(target => urlRe.test(target)).length;
|
|
203
297
|
const browserDetector = urlTargetCount > 1 ? await createBrowserDetector() : null;
|
|
204
298
|
|
|
205
299
|
try {
|
|
206
300
|
for (const target of paths) {
|
|
207
|
-
if (
|
|
301
|
+
if (urlRe.test(target)) {
|
|
302
|
+
// A file:// URL points at a local artifact, so its design system
|
|
303
|
+
// resolves from that file's project. A remote http(s) URL has no
|
|
304
|
+
// local project — it gets base options (no design system), never
|
|
305
|
+
// process.cwd()'s.
|
|
306
|
+
const urlOptions = /^file:/i.test(target)
|
|
307
|
+
? scanOptionsFor(fileUrlToLocalPath(target))
|
|
308
|
+
: baseScanOptions;
|
|
208
309
|
try {
|
|
209
310
|
const scanner = browserDetector
|
|
210
|
-
? (url) => browserDetector.detectUrl(url,
|
|
211
|
-
: (url) => detectUrl(url,
|
|
311
|
+
? (url) => browserDetector.detectUrl(url, urlOptions)
|
|
312
|
+
: (url) => detectUrl(url, urlOptions);
|
|
212
313
|
allFindings.push(...await scanner(target));
|
|
213
314
|
} catch (e) { process.stderr.write(`Error: ${e.message}\n`); }
|
|
214
315
|
continue;
|
|
@@ -274,11 +375,14 @@ async function detectCli() {
|
|
|
274
375
|
|
|
275
376
|
for (const file of files) {
|
|
276
377
|
const ext = path.extname(file).toLowerCase();
|
|
378
|
+
// Each file resolves its own project design system (cached by root),
|
|
379
|
+
// so a scan spanning sibling projects applies the right rules per file.
|
|
380
|
+
const fileOptions = scanOptionsFor(file);
|
|
277
381
|
let fileFindings;
|
|
278
382
|
if (HTML_EXTENSIONS.has(ext)) {
|
|
279
|
-
fileFindings = await detectHtml(file,
|
|
383
|
+
fileFindings = await detectHtml(file, fileOptions);
|
|
280
384
|
} else {
|
|
281
|
-
fileFindings = detectText(fs.readFileSync(file, 'utf-8'), file,
|
|
385
|
+
fileFindings = detectText(fs.readFileSync(file, 'utf-8'), file, fileOptions);
|
|
282
386
|
}
|
|
283
387
|
// Annotate findings with import context
|
|
284
388
|
const importers = importedByMap.get(file);
|
|
@@ -293,10 +397,11 @@ async function detectCli() {
|
|
|
293
397
|
} else if (stat.isFile()) {
|
|
294
398
|
if (shouldIgnoreDetectionFile(resolved, process.cwd(), detectionConfig)) continue;
|
|
295
399
|
const ext = path.extname(resolved).toLowerCase();
|
|
400
|
+
const fileOptions = scanOptionsFor(resolved);
|
|
296
401
|
if (HTML_EXTENSIONS.has(ext)) {
|
|
297
|
-
allFindings.push(...await detectHtml(resolved,
|
|
402
|
+
allFindings.push(...await detectHtml(resolved, fileOptions));
|
|
298
403
|
} else {
|
|
299
|
-
allFindings.push(...detectText(fs.readFileSync(resolved, 'utf-8'), resolved,
|
|
404
|
+
allFindings.push(...detectText(fs.readFileSync(resolved, 'utf-8'), resolved, fileOptions));
|
|
300
405
|
}
|
|
301
406
|
}
|
|
302
407
|
}
|
|
@@ -307,12 +412,24 @@ async function detectCli() {
|
|
|
307
412
|
|
|
308
413
|
allFindings = filterDetectionFindings(allFindings, detectionConfig);
|
|
309
414
|
allFindings = filterByScopes(allFindings, scopes);
|
|
415
|
+
// --no-advisory drops advisory findings before any output or exit-code math.
|
|
416
|
+
if (noAdvisory) allFindings = allFindings.filter((f) => !isAdvisory(f));
|
|
417
|
+
|
|
418
|
+
// The exit code and failure count reflect non-advisory findings only. An
|
|
419
|
+
// advisory-only scan still prints its notes but exits 0 (a clean pass), so
|
|
420
|
+
// advisory rules never break CI or block automation.
|
|
421
|
+
const { primary, advisory } = partitionAdvisory(allFindings);
|
|
310
422
|
|
|
311
423
|
if (allFindings.length > 0) {
|
|
312
424
|
if (jsonMode) process.stdout.write(formatFindings(allFindings, true) + '\n');
|
|
313
|
-
else if (quietMode)
|
|
425
|
+
else if (quietMode) {
|
|
426
|
+
process.stderr.write(formatFindingSummary(primary.length) + '\n');
|
|
427
|
+
if (advisory.length > 0) {
|
|
428
|
+
process.stderr.write(dim(`${advisory.length} advisory note${advisory.length === 1 ? '' : 's'} (not counted).`) + '\n');
|
|
429
|
+
}
|
|
430
|
+
}
|
|
314
431
|
else process.stderr.write(formatFindings(allFindings, false) + '\n');
|
|
315
|
-
process.exit(2);
|
|
432
|
+
process.exit(primary.length > 0 ? 2 : 0);
|
|
316
433
|
}
|
|
317
434
|
if (jsonMode) process.stdout.write('[]\n');
|
|
318
435
|
process.exit(0);
|