From 45148003af306dac6baa370f69ac7a543ee8acd8 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Wed, 2 Sep 2026 09:24:23 -0700 Subject: [PATCH] Fix detector review edge cases AI assistance disclosure: Codex implemented and verified these fixes under maintainer direction. --- cli/engine/browser/injected/index.mjs | 26 +++++++++++++++++-- cli/engine/detect-antipatterns-browser.js | 26 +++++++++++++++++-- cli/engine/engines/browser/detect-url.mjs | 4 +-- .../engines/static-html/detect-html.mjs | 4 +-- cli/engine/findings.mjs | 13 +++++++--- tests/detect-antipatterns-browser.test.mjs | 2 ++ .../antipatterns/linked-url-patterns.css | 14 ++++++++++ .../antipatterns/linked-url-patterns.html | 2 ++ 8 files changed, 79 insertions(+), 12 deletions(-) diff --git a/cli/engine/browser/injected/index.mjs b/cli/engine/browser/injected/index.mjs index 91c5370b7..3dfc3c266 100644 --- a/cli/engine/browser/injected/index.mjs +++ b/cli/engine/browser/injected/index.mjs @@ -1228,14 +1228,17 @@ if (IS_BROWSER) { isHidden: isElementHidden(el), findings: findings.map(f => { const ap = ANTIPATTERNS.find(a => a.id === (f.type || f.id)); + const severity = f.severity || ap?.severity || 'warning'; return { type: f.type || f.id, category: ap ? ap.category : 'quality', - severity: f.severity || ap?.severity || 'warning', + severity, // Advisory findings (em-dash overuse, etc.) are surfaced but never // treated as failures; carry the flag so the overlay/extension can // render them with the mildest affordance and consumers can filter. - advisory: ap?.severity === 'advisory' || f.severity === 'advisory' || f.advisory === true, + // Per-finding promotions override the registry default, so derive + // this strictly from the effective severity. + advisory: severity === 'advisory', detail: f.detail || f.snippet, ignoreValue: f.ignoreValue || f.value || '', name: ap ? ap.name : (f.type || f.id), @@ -1293,6 +1296,24 @@ if (IS_BROWSER) { catch { return null; } } + function conditionalCssRuleIsActive(rule) { + const type = Number(rule?.type); + const constructorName = rule?.constructor?.name || ''; + if (constructorName === 'CSSMediaRule' || type === 4) { + const condition = rule.conditionText || rule.media?.mediaText || ''; + if (!condition || typeof window.matchMedia !== 'function') return true; + try { return window.matchMedia(condition).matches; } + catch { return true; } + } + if (constructorName === 'CSSSupportsRule' || type === 12) { + const condition = rule.conditionText || ''; + if (!condition || typeof CSS === 'undefined' || typeof CSS.supports !== 'function') return true; + try { return CSS.supports(condition); } + catch { return true; } + } + return true; + } + // Read CSS that is absent from document.outerHTML. Inline