Skip to content

feat(no-unknown-classes): detect classes from Svelte style blocks - #376

Draft
iainlane wants to merge 1 commit into
schoero:mainfrom
iainlane:iainlane/detect-svelte-classes
Draft

feat(no-unknown-classes): detect classes from Svelte style blocks#376
iainlane wants to merge 1 commit into
schoero:mainfrom
iainlane:iainlane/detect-svelte-classes

Conversation

@iainlane

@iainlane iainlane commented May 4, 2026

Copy link
Copy Markdown

Svelte components routinely mix Tailwind utility classes with local component classes declared in the file's <style> block. When such a component is linted with no-unknown-classes, every local class is flagged as unknown because the rule only knows about Tailwind classes - it has no visibility into the component's scoped styles.

Add an opt-in detectSvelteStyleClasses option. When enabled, the rule treats every class selector declared in the component's <style> block as known for that file. Style blocks that use an unsupported language or contain malformed CSS silently fall back to detecting nothing, leaving the rule's existing behaviour unchanged for those files.

Previously,

<style>
  .card {
    border-radius: 0.5rem;
  }
</style>

<div class="card flex" />

would have failed with Unknown class detected: card. After this change, with detectSvelteStyleClasses: true, it passes.

@iainlane
iainlane force-pushed the iainlane/detect-svelte-classes branch from a0b002f to 6041474 Compare May 4, 2026 13:12
Svelte components routinely mix Tailwind utility classes with local
component classes declared in the file's `<style>` block. When such a
component is linted with `no-unknown-classes`, every local class is
flagged as unknown because the rule only knows about Tailwind classes -
it has no visibility into the component's scoped styles.

Add an opt-in `detectSvelteStyleClasses` option. When enabled, the rule
treats every class selector declared in the component's `<style>` block
as known for that file. Style blocks that use an unsupported language or
contain malformed CSS silently fall back to detecting nothing, leaving
the rule's existing behaviour unchanged for those files.

Previously,

```svelte
<style>
  .card {
    border-radius: 0.5rem;
  }
</style>

<div class="card flex" />
```

would have failed with `Unknown class detected: card`. After this
change, with `detectSvelteStyleClasses: true`, it passes.
@iainlane
iainlane force-pushed the iainlane/detect-svelte-classes branch from 6041474 to b14c1b9 Compare May 4, 2026 13:12
@bodograumann

Copy link
Copy Markdown

We need this for vue as well (or we would have to do some ignore acrobatics).
Is the approach introduced here viable, @schoero ?

@Norbiros

Norbiros commented Jul 6, 2026

Copy link
Copy Markdown

@schoero I would be happy to help with the implementation if you agree with this attempt

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.

3 participants