no-unchanged-state-variables
A state variable is changed by a variant, a state or a query.
- Severity
- warning
- Fixable
- no
Checks
Section titled “Checks”- A state variable (
--s-*) is written in at least one variant, state or query block of its element, or its value reads a variable that is (a private a variant changes, for example). A second write under@supportscounts too, directly or through a variable it reads: the value differs where the feature is supported. Otherwise it’s reported where its default is declared. - It holds on every element, a global one included:
html { --s-scroll-padding-block-start: … }. - The message is the same with or without
strict: in strict mode an unchanging property needs no variable either. - A state variable with no default, or taken with
inherit, isno-undeclared-state-variables’ error, not this rule’s. - Syntax core can’t read. An unknown in any of the element’s rules (an
@include), a write in a block core can’t classify (&:not(.quiet), or&.is-openon a class root), or a write whose value core can’t read may change it, so the variable isn’t reported. - Foreign elements (
:deep(),:global()) and utilities are skipped. - One finding for each written declaration: a selector list’s declaration is reported once, naming each element.
- There’s no
--fix. Moving the value onto the property removes a variable a later state may need.
A state variable exists so that variants and states can change one value in one place. If nothing changes it, it’s a plain value with an extra name, and the property can hold the value itself. Often it’s left over after a state was removed.
Nothing changes it
Section titled “Nothing changes it”Reported:
[data-component="card"] { --s-gap: var(--t-space-4); gap: var(--s-gap);}Fixed: the property holds the value.
[data-component="card"] { gap: var(--t-space-4);}Or a variant changes it:
[data-component="card"] { --s-gap: var(--t-space-4); gap: var(--s-gap); &[data-size="small"] { --s-gap: var(--t-space-2); }}Not reported
Section titled “Not reported”- Changed through a private:
--s-color: var(--_tone)with&[data-intent="danger"] { --_tone: red; }. - Changed by a query:
@media (width > 40rem) { --s-padding: 1rem; }in the element’s block, or by a feature query:@supports (display: grid) { --s-gap: 1rem; }. - A global element changed by a state:
html { … &:has([data-component="app-header"][data-sticky]) { --s-scroll-padding-block-start: 4rem; } }. - An
@includein one of the element’s rules.
Options
Section titled “Options”None.