Description
Classes imported in the main css file into the component layer are not recognized (better-tailwindcss/no-unknown-classes) after updating to v4.4.0, detectComponentClasses is enabled.
Flavor
CSS
Code Input
/* globals.css */
@import "../styles/example-a.css" layer(components);
@import "../styles/example-b.css" layer(components);
/* example-a.css */
.a-class {
@apply text-sm
}
/* example-b.css */
.b-class {
@apply text-md
}
Expected Behavior
Using a-class and b-class in the code without lint error.
Actual Behavior
The code example above is a simplified version, in my actual case, classes from one imported css file is are recognized, while the ones from the other file are not.
Reproduction URL
No response
ESLint Log
33:10 error Unknown class detected: cn-alert-dialog-overlay better-tailwindcss/no-unknown-classes
55:12 error Unknown class detected: cn-alert-dialog-content better-tailwindcss/no-unknown-classes
71:22 error Unknown class detected: cn-alert-dialog-header better-tailwindcss/no-unknown-classes
100:22 error Unknown class detected: cn-alert-dialog-media better-tailwindcss/no-unknown-classes
113:22 error Unknown class detected: cn-alert-dialog-title better-tailwindcss/no-unknown-classes
126:22 error Unknown class detected: cn-alert-dialog-description better-tailwindcss/no-unknown-classes
ESLint Config
{
files: ["**/*.tsx"],
plugins: {
"better-tailwindcss": eslintPluginBetterTailwindcss,
},
rules: {
...eslintPluginBetterTailwindcss.configs["recommended-error"].rules,
"better-tailwindcss/enforce-consistent-line-wrapping": "off", // Conflict with prettier
"better-tailwindcss/no-unknown-classes": [
"error",
{
ignore: [
"daisy-footer-center", // Can't detect correctly, https://github.com/saadeghi/daisyui/blob/master/packages/daisyui/src/components/footer.css#L10
],
},
],
"better-tailwindcss/enforce-shorthand-classes": "error",
"better-tailwindcss/enforce-consistent-important-position": "error",
},
settings: {
"better-tailwindcss": {
entryPoint: "src/app/globals.css",
detectComponentClasses: true,
selectors: [
...getDefaultSelectors(), // preserve default selectors
// See https://github.com/schoero/eslint-plugin-better-tailwindcss/blob/main/src/options/callees/cn.ts
{
kind: SelectorKind.Callee,
match: [{ type: MatcherType.String }],
name: "cnFast",
},
{
kind: SelectorKind.Callee,
match: [{ type: MatcherType.ObjectKey }],
name: "cnFast",
},
],
},
},
}
Versions
- ESLint: v10.2.0
- Parser: @typescript-eslint/parser v8.58.1
- Plugin: v4.4.0
- Node: v24.14.1
Description
Classes imported in the main css file into the component layer are not recognized (
better-tailwindcss/no-unknown-classes) after updating to v4.4.0,detectComponentClassesis enabled.Flavor
CSS
Code Input
Expected Behavior
Using
a-classandb-classin the code without lint error.Actual Behavior
The code example above is a simplified version, in my actual case, classes from one imported css file is are recognized, while the ones from the other file are not.
Reproduction URL
No response
ESLint Log
ESLint Config
Versions
Thanks for the reproduction.
The issue is actually in the package tailwind-csstree since v0.2.0. You can fix it by pinning the version of tailwind-csstree to v0.1.5.
Someone already made a PR that fixes it upstream: humanwhocodes/tailwind-csstree#58.