Add import groups configuration
See original GitHub issueSummary
My actual use-case is that I want React to be imported as first but I also want line breaking between my imports. If in the importOrder configuration I setup the following : "importOrder": ["^react", "^(?!react)\\w+$"] (from https://github.com/trivago/prettier-plugin-sort-imports/issues/7#issuecomment-739413024) with importOrderSeparation: true, it will add a line break between my imports from node_modules.
Actual behavior
import React from 'react'
import classnames from 'classnames'
Expected behavior
import React from 'react'
import classnames from 'classnames'
For the moment, if you want to importOrderSeparation, there is no way of configuring import groups. I think it could be awesome if we could specify in the configuration where is the line breaking.
Possible solution
Create a configuration like:
{
"importOrder": [
// no line breaking if specified in a sub-array
["^react", "^(?!react)\\w+$"],
"^[./]"
]
}
We could event remove the importOrderSeparation option because this way will allow you to put everything in the same block:
{
"importOrder": [
// no line breaking if specified in a sub-array
[
"^react",
"^(?!react)\\w+$",
"^[./]"
]
]
}
I’ll be glad to PR this 😉
Issue Analytics
- State:
- Created 3 years ago
- Comments:7

Top Related StackOverflow Question
I added PR #42 as implementation
I have re-open #42 due to the fact that it can help a lot of people and solve lot’s of issues. Let’s work on it and improve the PR.