Problem
The rhds/token-values stylelint rule reports a false positive when a token's fallback value is formatted across multiple lines. The rule compares the authored value (with whitespace preserved) against the canonical single-line value from tokens.get(name), so any multiline formatting causes a mismatch.
For example, this is flagged as an error:
color:
var(--rh-color-text-primary,
light-dark(
var(--rh-color-text-primary-on-light, #151515),
var(--rh-color-text-primary-on-dark, #ffffff)
)
);
Even though the value is semantically identical to the single-line form:
color: var(--rh-color-text-primary, light-dark(var(--rh-color-text-primary-on-light, #151515), var(--rh-color-text-primary-on-dark, #ffffff)));
Root cause
In token-values.ts, the comparison at line ~47 uses parser.stringify(values) which preserves authored whitespace (newlines, indentation). The expected value from tokens.get(name) is always single-line. The two never match when the authored CSS is multiline.
Suggested fix
Normalize whitespace before comparing:
function normalizeWhitespace(s: string) {
return s.replace(/\s+/g, ' ').trim();
}
Then update the comparison:
- if ((expected as string)?.toString() !== actual) {
+ if (normalizeWhitespace((expected as string)?.toString()) !== normalizeWhitespace(actual)) {
The fix() function does not need changes since it already writes the canonical single-line value. With the normalized comparison, fix() will only fire when the actual token value is wrong -- not when only the whitespace formatting differs. This avoids a conflict where fix() collapses multiline values to a single line, which could then trigger a line-length violation.
Problem
The
rhds/token-valuesstylelint rule reports a false positive when a token's fallback value is formatted across multiple lines. The rule compares the authored value (with whitespace preserved) against the canonical single-line value fromtokens.get(name), so any multiline formatting causes a mismatch.For example, this is flagged as an error:
Even though the value is semantically identical to the single-line form:
Root cause
In
token-values.ts, the comparison at line ~47 usesparser.stringify(values)which preserves authored whitespace (newlines, indentation). The expected value fromtokens.get(name)is always single-line. The two never match when the authored CSS is multiline.Suggested fix
Normalize whitespace before comparing:
Then update the comparison:
The
fix()function does not need changes since it already writes the canonical single-line value. With the normalized comparison,fix()will only fire when the actual token value is wrong -- not when only the whitespace formatting differs. This avoids a conflict wherefix()collapses multiline values to a single line, which could then trigger a line-length violation.