Specify import groups and automatic add blank lines between them #645
Replies: 10 comments 16 replies
-
I am not sure about the safety of this option. I don't know anything about the plugin you mentioned, so I will speak about Biome. Hard lines in our import sorting are vital for users to move side effects modules where the user needs: https://biomejs.dev/analyzer/#grouped-imports If we decided on an option like the one you mentioned, we wouldn't be able to support this behaviour, or we would risk adding too many options, making it too complex. What do you think? As I said, I don't know the plugin, so I might have missed something |
Beta Was this translation helpful? Give feedback.
-
Another way to sort imports is to use Prettier plugin https://github.com/trivago/prettier-plugin-sort-imports . But since we moved from Prettier to Biome for formatting, it's no longer possible to use that. :( I think it would be fine not to have too many options about this, but I'd like to be able to follow the convention from that plugin (or eslint-plugin-import). Well, the settings that I'd like to be able to use with biome are these from the prettier plugin. This resulted same order as what Typescript's Organize imports was doing before version 5. Which means, that there will be at least 2 groups: one group for "external imports" and one group for "local imports". And there is empty line between them for separation.
I think there are a lot motivation for this kind of grouping. One big motivation for me, is to able to easily scan what that file is using from external imports. And if you have accidentally imported something from external package, when you meant to import symbol from local project. |
Beta Was this translation helpful? Give feedback.
-
I am using an alternative way to fix this. If you are using VSCode you can add this to your
Also, if you want to use your own order you can use extensions like https://marketplace.visualstudio.com/items?itemName=alfnielsen.vsc-organize-imports |
Beta Was this translation helpful? Give feedback.
-
Would also love this feature. I'm considering migrating to Biome from Prettier where I use the prettier plugin from Trivago like @rubiesonthesky . From all import sorting tools I've tried, it seems to be the most flexible and reliable. |
Beta Was this translation helpful? Give feedback.
-
Regarding the custom import order; we currently also make use of Trivago's prettier sort imports plugin, which uses an array of regular expressions to customize the import order. The plugin has 739,534+ weekly downloads, which does suggests it's a wanted features by the community. |
Beta Was this translation helpful? Give feedback.
-
I also make use of the Trivago plugin for Pretterier across various projects. It helps to simplify commit diff comparisons since imports end in the same order unless new imports are introduced in a change. Excellent feature to have. |
Beta Was this translation helpful? Give feedback.
-
Seems like Biome organizeImports is quite stable right now. Also adding other library that is popular for sorting imports: "importOrder": [
"<TYPES>",
"",
"^react",
"<THIRD_PARTY_MODULES>",
"",
"^~/layouts(.*)$",
"^~/components(.*)$",
"",
"^~/hooks(.*)$",
"^~/lib(.*)$",
"",
"^~/assets(.*)$",
"^~/styles(.*)$",
"",
"^[./]"
], |
Beta Was this translation helpful? Give feedback.
-
One thing that is missing atm is support for custom path like
theme is in fact an "absolute" internal import, and should thus be found after the style-component node_module import 🤔 |
Beta Was this translation helpful? Give feedback.
-
this is the ticket with top activity, but still not getting any attention from the authors - why? 😔 |
Beta Was this translation helpful? Give feedback.
-
Closing. Please jump in #3015 where a great RFC awaits you |
Beta Was this translation helpful? Give feedback.
-
eslint-plugin-import
has a nice feature to automatic add blank lines between import groups, I also miss the ability to define custom import groups, something like this:This will resolve to:
Groups specified in arrays will be combined together:
addBlankLinesBetweenImports
take aboolean
and isfalse
by defaultimportGroups
take aboolean
or anarray
and istrue
by default, which will follow the default order specified in docs:Related eslint links:
Beta Was this translation helpful? Give feedback.
All reactions