Skip to content

fix(extractors): skip style declarations in object literals, for every framework - #219

Merged
sergioazoc merged 1 commit into
mainfrom
fix/style-object-keys
Oct 8, 2026
Merged

sergioazoc merged 1 commit into
mainfrom
fix/style-object-keys

Conversation

@sergioazoc

Copy link
Copy Markdown
Owner

What & why

Follow-up to #214, which stopped reading -- keys as classes. The default ^styles?$ variable pattern reaches the style objects of every framework, not only React's CSSProperties, so the remaining cases still reported:

const style = { 'background-color': color() }   // Solid, Vue, Qwik, Lit styleMap
const style = { '-webkit-line-clamp': lines }    // vendor prefix
const styles = { 'width.px': 240 }               // Angular ngStyle
cn({ '--x flex': c })                            // #214 skipped `flex` here (false negative)

An object key is now skipped when it is a style declaration (isStyleDeclaration in extractors.ts):

  • Custom property, as one token: /^--\S+$/. '--x flex' is read as classes again.
  • CSS property name: utils/css-properties.ts, csstype's standard + SVG *PropertiesHyphen names plus the -ms- ones, minus the 15 that are also Tailwind classes (flex, grid, border, container, transition, …). A test holds that no name in the list is a class.
  • Vendor prefix: -webkit- / -moz- by prefix. -ms- only by name, since -ms-4 is a negative margin.
  • Constant value: a string, number or template literal. In a class map the value is a condition; a constant one never is ({ flex: '1 1 0%' }, 'width.px': 240, { 'primary-button': 'bg-blue-500' }).

Every other key is still a class (cn({ 'itms-center': isOpen }) is still reported).

Tests

  • style-declaration object keys block in tests/rules/no-unknown-classes.test.ts: framework cases (valid) and the token / -ms-4 edges (invalid).
  • CSS_PROPERTY_NAMES holds no Tailwind class, against the default fixture.
  • pnpm lint && pnpm format:check && pnpm typecheck && pnpm build && pnpm test: 3522 + 312 passing.

Docs

/settings (EN + ES) explains which object keys are read; the Unreleased CHANGELOG entry from #214 is rewritten to cover the whole change; CLAUDE.md updated.

Refs #5, #214

🤖 Generated with Claude Code

https://claude.ai/code/session_019vTh6S5A41M1HLkmk3FaM1

…y framework

#214 skipped a key starting with `--`. The default `^styles?$` variable
pattern reaches the style objects of every framework, not only React's
custom properties, so a key is now skipped when it is a style declaration:

- a custom property, as one token (`'--x flex'` is still read as classes);
- a CSS property name (Solid, Vue, Qwik and Lit's kebab-case keys), from
  csstype minus the 15 names that are also Tailwind classes, held by a test;
- a `-webkit-` / `-moz-` property by prefix, `-ms-` by name (`-ms-4` is a
  negative margin);
- a key whose value is a string, number or template literal (Angular's
  `'width.px': 240`, lookup maps): a class map's value is a condition.

Claude-Session: https://claude.ai/code/session_019vTh6S5A41M1HLkmk3FaM1
@sergioazoc
sergioazoc merged commit 26f8af2 into main Oct 8, 2026
11 checks passed
@sergioazoc
sergioazoc deleted the fix/style-object-keys branch October 8, 2026 01: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