You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @alixsep! We’ve had this come up a few times. This is actually expected behavior, and here’s why:
CSS has a hierarchy, and later-declarations have higher precedence than earlier ones. This means if we re-organized the CSS imports, we would change the styling of your page.
This means we choose not to sort CSS imports like your example — because it’s generally unsafe.
This isn’t an “special case” that we’ve put in for CSS, it actually happens to also apply to JS (because things in the global scope can be manipulated by JS, and later imports can depend on side-effects of earlier imports). The compromise there is that if you pluck values out of a JS import, then we assume you’re probably not expecting side-effects, but if you have an expression that introduces no names import “side-effect-only”, then we know that import is only for the side-effects.
If you used a CSS-in-JS technique and imported the CSS into a named import, then we’d be able to sort it.
Hope this helps, and sorry this is probably not the news you were looking for!
Your Environment
Describe the bug
The order of imports after formatting with prettier doesn't follow the one defined in prettier configuration file when a CSS file is being imported.
To Reproduce
I have this file (unformatted):
and this is my config file for prettier (.prettierrc.cjs):
and this is the result that i get after formatting:
which is wrong; as I expect my formatted file to look like this:
Error log
No errors, and this is the log of prettier in my output:
Contribute to @ianvs/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: