Skip to content

Report unknown custom properties/media as warning, not error#151

Merged
marcusosterberg merged 1 commit into
mainfrom
fix/custom-property-rules-as-warning
Jun 12, 2026
Merged

Report unknown custom properties/media as warning, not error#151
marcusosterberg merged 1 commit into
mainfrom
fix/custom-property-rules-as-warning

Conversation

@marcusosterberg

Copy link
Copy Markdown
Contributor

What

Downgrade no-unknown-custom-properties and no-unknown-custom-media from error to warning.

Why

Both rules assert a negative — that a referenced custom property / custom media query is defined nowhere. Unlike rules that detect genuinely malformed CSS (property-no-unknown, color-no-invalid-hex, …), this can't be verified by static analysis of the CSS captured from a single crawled page. Custom properties are legitimately defined in places the linter never sees:

  • set at runtime via JS (element.style.setProperty('--x', …)) — common for theming / dark mode,
  • set in inline style="--x: …" attributes,
  • defined in a :root/section block on a page that wasn't the one crawled,
  • (custom media) produced at build time by PostCSS and absent from delivered CSS.

A missing custom property also degrades gracefullyvar(--undefined) with no fallback becomes invalid-at-computed-value-time and falls back to the initial/inherited value, rather than producing invalid CSS. That is warning-shaped, not error-shaped.

Real example that prompted this: https://tillvaxtverket.se references four --lp-filterable-list__control--* theming hooks it never defines. The page renders fine (the inputs just use default styling), but the finding was reported as error (fel) and pulled down the standards grade.

Notes

  • configurations/standard.json is generated, so the change is in tools/update_stylelint.py; the regenerated standard.json is included and is byte-identical to a fresh run against the pinned stylelint 17.12.0.
  • All other no-unknown-* rules stay at error.

no-unknown-custom-properties and no-unknown-custom-media assert that a
referenced custom property/media query is defined nowhere. Static analysis
of the CSS captured from a single crawled page can't see definitions set at
runtime via JS, in inline style attributes, on a page that wasn't crawled,
or produced at build time by PostCSS, so error severity yields frequent
false positives. A missing custom property also degrades gracefully to the
initial/inherited value rather than producing invalid CSS. Downgrade both
to warning so they stay visible without counting as standards errors.
@marcusosterberg marcusosterberg merged commit f0da12c into main Jun 12, 2026
1 check passed
@marcusosterberg marcusosterberg deleted the fix/custom-property-rules-as-warning branch June 12, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant