question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent reordering css imports

See original GitHub issue

Sometimes the order of my css imports matters, because it will effect the cascade. Is there a way I can prevent the sort algorithm from operating against my css files and making them alphabetical?

Or maybe there’s a comment I can use to prevent reordering particular sections / files? For instance in my index.tsx file I need to import my global css file before my app component, again for the cascade. Prettier itself has no ranged-ignore comments, unfortunately. https://github.com/prettier/prettier/issues/5287

Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
IanVScommented, Mar 12, 2022

@adroste, I also agree this is important, enough that I published a fork of this project that includes https://github.com/trivago/prettier-plugin-sort-imports/pull/111, so that side-effect imports are not reordered. You can find that fork at https://www.npmjs.com/package/@ianvs/prettier-plugin-sort-imports, in case it’s useful.

1reaction
IdanLevicommented, Jan 11, 2022

Personally (my opinion, not the opinion of the the author(s) of this plugin) I think we should keep it as simple as possible. Having to add prettier or plugin specific comments to change the sorting order might be a last workaround, but it feels wrong to me – it should “just work” without these magic comments.

Having to manually group you CSS imports into sort groups also feels like a chore and sounds pretty fragile when the content of these files changes. And I think we should also keep in mind that adding too many code style options is also kinda against the spirit of prettier.

So perhaps we can collect more uses cases CSS imports like import styles from './myButton.module.css';? Should these never be sorted because the order is important, or are there some cases when people want to sort them and some cases when people don’t want them to be sorted?

If the former we could simply never sort CSS imports. If the latter, a simple option like sortCssImports might help?

I think a ‘sortCssImports’ option would be great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the Angular Material 2 CSS imports order?
Yes, In Angular material it adds the intern CSS dynamically when the element/component gets load. So, you cannot change its order.
Read more >
order - CSS: Cascading Style Sheets - MDN Web Docs
The order CSS property sets the order to lay out an item in a flex or grid container. Items in a container are...
Read more >
Disable wordpress reordering functions in backend screen ...
You have to add the following CSS to an admin.css file (name it whatever you like but it has to be a css...
Read more >
sort-imports - ESLint - Pluggable JavaScript Linter
js' is corrected to import { a, b } from 'foo.js' ), but multiple lines are not reordered. Options. This rule accepts an...
Read more >
Ability to reorder Styles (CSS) in Style Manager Merged
Since I build web apps template in Webflow, having the ability to drag and rearrange the CSS styles created in Style Manager would...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found