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

@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

Motivation:
The com.nequissimus:sort-imports:0.6.1 scalafix plugin is outdated and
no longer maintained. Scalafix's built-in OrganizeImports rule provides
equivalent functionality with better integration and active maintenance.

Modification:
- Replace SortImports rule with OrganizeImports in .scalafix.conf
- Remove sort-imports dependency from ScalaFixExtraRulesPlugin
- Update sortImports command alias to use OrganizeImports
- Add -Wunused:imports to scalac options (required by removeUnused)
- Configure import groups to match Pekko's existing style:
  java/scala/com.sun first, then org.apache.pekko and pekko.* imports,
  followed by third-party libraries
- Remove SortImports from .scalafmt.conf rewrite rules
- Add JDK21-only test files to ignored-files (no SemanticDB available)
- Set RemoveUnused.imports = false to avoid conflict with OrganizeImports

Result:
Import formatting now uses scalafix's built-in OrganizeImports rule with
removeUnused = true, which also cleans up accumulated unused imports.
The sort-imports external dependency is no longer needed.

Tests:
sbt sortImports (scalafixEnable + scalafixAll OrganizeImports + scalafmtAll)

References:
None - build tooling improvement
@He-Pin He-Pin force-pushed the refactor/replace-sort-imports-with-organize-imports branch from 19368ae to 8131b4b Compare July 14, 2026 02:50
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