Skip to content

refactor: replace sort-imports plugin with scalafix OrganizeImports#3342

Draft
He-Pin wants to merge 1 commit into
mainfrom
refactor/replace-sort-imports-with-organize-imports
Draft

refactor: replace sort-imports plugin with scalafix OrganizeImports#3342
He-Pin wants to merge 1 commit into
mainfrom
refactor/replace-sort-imports-with-organize-imports

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 13, 2026

Copy link
Copy Markdown
Member

Motivation

The com.nequissimus:sort-imports:0.6.1 plugin has not been updated since December 2021 and is effectively unmaintained. Scalafix's built-in OrganizeImports rule (available since 0.11.0, project uses 0.14.7) is more powerful, actively maintained, and requires no external dependency.

Modification

  • Replace SortImports rule with OrganizeImports in .scalafix.conf, configured with 10 import groups matching Pekko's existing style (java/javax, scala, third-party, com.sun, pekko/akka, reactivestreams, netty, scalatest, slf4j, typesafe)
  • Remove SortImports from .scalafmt.conf rewrite.rules to avoid conflict with scalafix
  • Remove com.nequissimus:sort-imports:0.6.1 dependency from ScalaFixExtraRulesPlugin
  • Update sortImports command alias in build.sbt, ScalaFixForJdk21Plugin, and ScalafixForMultiNodePlugin to use OrganizeImports
  • Add -Wunused:imports compiler option for Scala 2.13 and Scala 3 to support OrganizeImports.removeUnused
  • Disable RemoveUnused.imports (conflicts with OrganizeImports) and enable OrganizeImports.removeUnused = true instead
  • Apply full project import reformatting across all main and test sources (1991 files)

Result

Import sorting now uses scalafix's built-in OrganizeImports rule with no external dependency. The sbt sortImports command continues to work as before, now also automatically removing unused imports. Import grouping matches Pekko's existing style with 10 configured groups.

Tests

  • sbt "Test / compile" passed with Java 21

References

None - build tooling improvement

Motivation:
The com.nequissimus:sort-imports:0.6.1 plugin has not been updated since
December 2021 and is effectively unmaintained. Scalafix's built-in
OrganizeImports rule (available since 0.11.0) is more powerful, actively
maintained, and requires no external dependency.

Modification:
- Replace SortImports rule with OrganizeImports in .scalafix.conf,
  configured with 10 import groups matching Pekko's existing style
- Remove SortImports from .scalafmt.conf rewrite.rules to avoid conflict
- Remove com.nequissimus:sort-imports:0.6.1 dependency
- Update sortImports command alias to use OrganizeImports
- Add -Wunused:imports compiler option for Scala 2.13 and Scala 3
- Disable RemoveUnused.imports (conflicts with OrganizeImports) and
  enable OrganizeImports.removeUnused instead
- Add JDK21-only test files to ignored-files list
- Apply full project import reformatting (main + test sources)

Result:
Import sorting uses scalafix's built-in OrganizeImports rule with no
external dependency. The sortImports command continues to work as before,
now also removing unused imports automatically.

Tests:
- sbt sortImports completed successfully with Java 21

References:
None - build tooling improvement
@He-Pin He-Pin force-pushed the refactor/replace-sort-imports-with-organize-imports branch from ba97a4b to 19368ae Compare July 13, 2026 18:28
Comment thread build.sbt
@@ -48,7 +48,7 @@ addCommandAlias(
name = "fixall",
value = ";scalafixEnable; scalafixAll; scalafmtAll; test:compile; multi-jvm:compile; reload")

addCommandAlias(name = "sortImports", value = ";scalafixEnable; scalafixAll SortImports; scalafmtAll")
addCommandAlias(name = "sortImports", value = ";scalafixEnable; scalafixAll OrganizeImports; scalafmtAll")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizeImports

@He-Pin He-Pin marked this pull request as draft July 13, 2026 18:35
import scala.util.control.NonFatal

import org.apache.pekko

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a change that I prefer that we fix - let's keep no gap between the org.apache.pekko import and the pekko imports

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still tweaking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants