-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
💡 Handle @import
statements in CSS and superset languages
#945
Comments
SeparatelySASS/SCSS imports, particularly from
So maybe that can be skipped for now, whereas a keyword-less |
Thanks for the input, that's valuable. The reason it's not built-in and how to add your own compiler is here: https://knip.dev/features/compilers#css Based on the various syntaxes, enabling some default "compiler" sounds risky. I think I'd rather have users enable it explicitly than having to disable it after weird reports. However, I'd be open to a pull request (ideally without extra dependencies) if the chances of false positives/odd results are slim enough. |
One thing to note is that
But for now I used this config and it gives some results already: function cssImportParser (text, filename) {
return [...text.matchAll(/(?<=@)import[^;]+/g)].join('\n');
}
export default {
compilers: {
scss: cssImportParser,
css: cssImportParser,
},
}; It would be cool to see minimal support native in knip, at least for CSS. SCSS also has additional lookup logic like |
So for the reasons given I currently think it's not a good idea to add this compiler to Knip natively. Compilers can be added at will and handle the locally used file formats and syntaxes properly. |
Suggest an idea for Knip
I didn't find any open requests other than a mention in:
I think that at a minimum it would be good to parse plain relative imports, like:
With a few extra non-relevant keywords that might follow: https://developer.mozilla.org/en-US/docs/Web/CSS/@import
Here's the docs for
url()
: https://developer.mozilla.org/en-US/docs/Web/CSS/url_functionIt might be simple enough to parse via regex, but if not, Lightning CSS might be a fast parser (also supporting other languages)
http
imports are also valid but obviously not applicable here.The text was updated successfully, but these errors were encountered: