-
-
Notifications
You must be signed in to change notification settings - Fork 3
Feature Request: no-unregistered-classes #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So it would be more like a "no-invalid-classes" or "no-unregistered-classes" rule if I understand it correctly. We already load the tailwind context for the "sort-classes" rule and the tailwind context knows all registered classes, so it should be possible to just ask tailwind if the class is valid, at least in theory. |
"no-unregistered-classes" would be a great name for that! Could something like |
I did some testing and the rule is pretty simple to implement. We can basically just ask tailwind what the css for a given class will be, and if it returns Dynamic values only work for |
This sounds amazing. I hope I can get you into our open source sponsoring round that we have at our company at the end of every year 🤩 |
This might harder than I initially thought. The problem is that some valid tailwindcss classes like I got normal classes working for tailwindcss v3 and v4 though. You can beta test the other functionality by installing The documentation for the new rule is here You can add |
Wow, this seems to work great. We just started migrating from styled-components to Tailwind in a big project and this already catches a couple of dead/wrong classes. Kudos! |
Thank you for the feedback. I enabled the rule in some projects of mine for testing and it revealed some minor bugs for me too 😄. I can really see the usefulness of this rule. If the So if you find any other false positives, please report them back. |
So far I haven't seen false positives. Thanks! |
I have published a new version on the That said, I’m starting to think this rule doesn’t quite align with the original purpose of this ESLint plugin. The original idea was basically just the multiline rule to improve readability. At the time, I used it alongside eslint-plugin-tailwindcss, which worked really well. Over time, I ran into problems with some of its rules, so I started to reimplement them in this plugin, but they always fit the "readability improvement" narrative and I could even improve some of the functionality. This new rule can't really provide an autofix, which in my opinion is the biggest break with the original intention. On the other hand, the approach I used in this rule also opens up great new possibilities for other rules. For example, I could add a Long story short: I think it might be time to give the plugin a more general name and restructure it a bit. |
Thank for being so open about this thought process. 😊 |
Hi!
Would it be possible to check for unused classes in a new linter rule? E.g. if I use something like
--color-*: initial;
and define my own color tokens that the linter errors on usages likebg-sky-600
ortext-gray-950
.I imagine it looks for classes that follow the known utility patterns like
text-*
,bg-*
, etc. and if*
is a literal it checks if there is registered token for it. This isn't just useful for people who change tokens, but can also catch typos likebg-syk-600
.The text was updated successfully, but these errors were encountered: