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

Commit

Permalink
Fix #96
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Jul 18, 2020
1 parent ed9bf80 commit e2e5887
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rules/src/main/scala/fix/OrganizeImports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,21 @@ class OrganizeImports(config: OrganizeImportsConfig) extends SemanticRule("Organ
}

private def organizeImportGroup(importers: Seq[Importer]): Seq[Importer] = {
// Issue #96: For importers with only a single `Importee.Name` importee, if the importee is
// curly-braced, remove the curly-braces. For example: `import p.{X}` should be rewritten into
// `import p.X`. Here we invoke `.copy()` to erase the source position information from the
// original importer, so that when this importer is preserved in the result, the pretty-printer
// formats it without the unneeded curly-braces.
val noUnneededBraces = importers map {
case importer @ Importer(_, Importee.Name(_) :: Nil) => importer.copy()
case importer => importer
}

val importeesSorted = locally {
config.groupedImports match {
case GroupedImports.Merge => mergeImporters(importers)
case GroupedImports.Explode => explodeImportees(importers)
case GroupedImports.Keep => importers
case GroupedImports.Merge => mergeImporters(noUnneededBraces)
case GroupedImports.Explode => explodeImportees(noUnneededBraces)
case GroupedImports.Keep => noUnneededBraces
}
} map (coalesceImportees _ andThen sortImportees)

Expand Down

0 comments on commit e2e5887

Please sign in to comment.