Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Ability to control blank lines between groups #140

Closed
nafg opened this issue Dec 13, 2020 · 6 comments · Fixed by #142
Closed

Ability to control blank lines between groups #140

nafg opened this issue Dec 13, 2020 · 6 comments · Fixed by #142
Labels
enhancement New feature or request

Comments

@nafg
Copy link

nafg commented Dec 13, 2020

I would like to reproduce my intellij config as closely as possible. In .idea/codeStyles/Project.xml I have this:

      <option name="importLayout">
        <array>
          <option value="java" />
          <option value="_______ blank line _______" />
          <option value="scala" />
          <option value="_______ blank line _______" />
          <option value="org.scalajs" />
          <option value="play" />
          <option value="net.liftweb" />
          <option value="reactive" />
          <option value="slick" />
          <option value="japgolly" />
          <option value="io.github.nafg" />
          <option value="_______ blank line _______" />
          <option value="all other imports" />
          <option value="_______ blank line _______" />
          <option value="chesednow" />
        </array>
      </option>

So for example, imports from japgolly should always go before imports from io.github.nafg, however I don't want a blank line between them.

Is there any way to achieve this, or could there be?

@liancheng liancheng added the enhancement New feature or request label Dec 15, 2020
@liancheng
Copy link
Owner

liancheng commented Dec 15, 2020

@nafg, that's a nice feature request. It cannot be done today but can be added relatively easily. I'd add one configuration named blankLines and a special group - representing the blank line.

When blankLines is set to Auto, which is the default value, OrganizeImports respects the current behavior, i.e., a blank line is automatically inserted between adjacent groups. When blankLines is set to Manual, you need to add the - group to insert blank lines manually.

With this, your sample configuration can be translated into:

OrganizeImports {
  blankLines = "Manual"
  groups = [
    "re:javax?\\."
    "-"
    "scala."
    "-"
    "org.scalajs."
    "play."
    "net.liftweb."
    "reactive."
    "slick."
    "japgolly."
    "io.github.nafg."
    "-"
    "*"
    "-"
    "chesednow"
  ]
}

WDYT?

@liancheng
Copy link
Owner

Maybe use --- instead of - to make the blank line groups easier to locate visually.

@nafg
Copy link
Author

nafg commented Dec 15, 2020 via email

@liancheng
Copy link
Owner

liancheng commented Dec 16, 2020

@nafg I had a draft implementation for this feature in PR #142. It turned out to be much hairier than I initially expected. I'll try to see whether things can be refactored and simplified. On the other hand, here's a workaround that largely satisfies your requirement. You can configure the OrganizeImports as following:

OrganizeImports {
  groups = [
    "re:javax?\\."
    "scala."
    "re:(org\\.scalajs|play|net\\.liftweb|reactive|slick|japgolly|io\\.github\\.nafg)\\."
    "*"
    "chesednow"
  ]
}

The only thing is that the 3rd group will sort all the imports in that group according to the importsOrder configuration, so it does not strictly reflect the original order you wanted. However, I think it makes more sense to order them alphabetically instead of using an ad-hoc order? Are there any reasons why you prefer the specific order you listed in the PR description? (I get that it eases migration if your IntelliJ is already configured like that.)

@nafg
Copy link
Author

nafg commented Dec 17, 2020 via email

@liancheng
Copy link
Owner

@nafg, thanks for the context. So it's for migrating existing projects using IntelliJ import optimizer to OrganizeImports. That totally makes sense. Let me try to find some time to refactor #142 and add tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants