From 6415ed191420a91dc28d3f0b01d0318b32a59053 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Sun, 28 Jan 2024 22:28:55 +0100 Subject: [PATCH] OrganizeImports: support Scala3 syntax as output --- docs/rules/OrganizeImports.md | 22 ++++- .../internal/rule/OrganizeImports.scala | 80 +++++++++++++++++-- .../organizeImports/TargetDialectAuto.scala | 13 +++ ...ialectSingleImporteeStripCurlybraces.scala | 12 +++ .../CoalesceImporteesGivensAndNames.scala | 1 + .../CoalesceImporteesNoGivens.scala | 1 + .../CoalesceImporteesNoGivensNoNames.scala | 1 + .../CoalesceImporteesNoNames.scala | 1 + .../DeduplicateGivenImportees.scala | 1 + .../test/organizeImports/ExpandGiven.scala | 3 +- .../organizeImports/ExpandUnimportGiven.scala | 1 + .../GroupedGivenImportsMergeUnimports.scala | 19 ++--- ...roupedImportsAggressiveMergeGivenAll.scala | 1 + .../test/organizeImports/MergeGiven.scala | 6 +- .../MergeImportsFormatPreservingGiven.scala | 13 +++ .../TargetDialectDowngrade.scala | 11 +++ ...ialectSingleImporteeStripCurlybraces.scala | 17 ++++ .../organizeImports/AlreadyOrganized.scala | 3 +- .../organizeImports/CoalesceImportees.scala | 1 + .../CurlyBracedSingleImportee.scala | 2 + .../ExpandRelativeRootPackage.scala | 1 + .../ExplodeImportsFormatPreserving.scala | 3 +- ...roupedImportsAggressiveMergeWildcard.scala | 1 + .../GroupedImportsExplodeMixed.scala | 1 + .../GroupedImportsExplodeUnimport.scala | 1 + .../GroupedImportsMergeDedup.scala | 1 + .../GroupedImportsMergeRenames.scala | 1 + .../GroupedImportsMergeUnimports.scala | 1 + .../GroupedImportsMergeWildcard.scala | 1 + .../organizeImports/ImportsOrderKeep.scala | 1 + .../ImportsOrderSymbolsFirst.scala | 4 + .../MergeImportsFormatPreserving.scala | 3 +- .../organizeImports/TargetDialectAuto.scala | 6 ++ .../organizeImports/AlreadyOrganized.scala | 2 +- .../organizeImports/CoalesceImportees.scala | 0 .../CurlyBracedSingleImportee.scala | 1 + .../ExplodeImportsFormatPreserving.scala | 0 ...roupedImportsAggressiveMergeWildcard.scala | 0 .../GroupedImportsExplodeMixed.scala | 0 .../GroupedImportsExplodeUnimport.scala | 0 .../GroupedImportsMergeDedup.scala | 0 .../GroupedImportsMergeRenames.scala | 0 .../GroupedImportsMergeUnimports.scala | 0 .../GroupedImportsMergeWildcard.scala | 0 .../organizeImports/ImportsOrderKeep.scala | 0 .../ImportsOrderSymbolsFirst.scala | 3 + .../MergeImportsFormatPreserving.scala | 2 +- ...ialectSingleImporteeStripCurlybraces.scala | 7 ++ .../organizeImports/AlreadyOrganized.scala | 10 +++ .../organizeImports/CoalesceImportees.scala | 8 ++ .../CoalesceImporteesGivensAndNames.scala | 4 +- .../CoalesceImporteesNoGivens.scala | 2 +- .../CoalesceImporteesNoGivensNoNames.scala | 2 +- .../CoalesceImporteesNoNames.scala | 4 +- .../CurlyBracedSingleImportee.scala | 7 ++ .../DeduplicateGivenImportees.scala | 2 +- .../test/organizeImports/ExpandGiven.scala | 1 + .../organizeImports/ExpandUnimportGiven.scala | 4 +- .../ExplodeImportsFormatPreserving.scala | 7 ++ .../GroupedGivenImportsMergeUnimports.scala | 6 +- ...roupedImportsAggressiveMergeGivenAll.scala | 8 +- ...roupedImportsAggressiveMergeWildcard.scala | 7 ++ .../GroupedImportsExplodeMixed.scala | 7 ++ .../GroupedImportsExplodeUnimport.scala | 5 ++ .../GroupedImportsMergeDedup.scala | 5 ++ .../GroupedImportsMergeRenames.scala | 7 ++ .../GroupedImportsMergeUnimports.scala | 6 ++ .../GroupedImportsMergeWildcard.scala | 7 ++ .../organizeImports/ImportsOrderKeep.scala | 12 +++ .../ImportsOrderSymbolsFirst.scala | 15 ++++ .../test/organizeImports/MergeGiven.scala | 2 +- .../MergeImportsFormatPreserving.scala | 7 ++ .../MergeImportsFormatPreservingGiven.scala | 6 ++ .../TargetDialectDowngrade.scala | 6 ++ ...ialectSingleImporteeStripCurlybraces.scala | 12 +++ 75 files changed, 373 insertions(+), 45 deletions(-) create mode 100644 scalafix-tests/input/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala create mode 100644 scalafix-tests/input/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala create mode 100644 scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala create mode 100644 scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala create mode 100644 scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala create mode 100644 scalafix-tests/output/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/AlreadyOrganized.scala (91%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/CoalesceImportees.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/CurlyBracedSingleImportee.scala (79%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/ExplodeImportsFormatPreserving.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsExplodeMixed.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsExplodeUnimport.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsMergeDedup.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsMergeRenames.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsMergeUnimports.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/GroupedImportsMergeWildcard.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/ImportsOrderKeep.scala (100%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/ImportsOrderSymbolsFirst.scala (69%) rename scalafix-tests/output/src/main/{scala => scala-2}/test/organizeImports/MergeImportsFormatPreserving.scala (96%) create mode 100644 scalafix-tests/output/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/AlreadyOrganized.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImportees.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/CurlyBracedSingleImportee.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/ExplodeImportsFormatPreserving.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeMixed.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeUnimport.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeDedup.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeRenames.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeUnimports.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeWildcard.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderKeep.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderSymbolsFirst.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreserving.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala create mode 100644 scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala diff --git a/docs/rules/OrganizeImports.md b/docs/rules/OrganizeImports.md index 5939f2533b..72be45870f 100644 --- a/docs/rules/OrganizeImports.md +++ b/docs/rules/OrganizeImports.md @@ -1342,16 +1342,18 @@ Enum: `Auto | Scala2 | Scala3` #### `Auto` Infer the dialect from compilation settings (Scala version or `-Xsource` when -provided). This is safe only for sources that are not cross-compiled (see -rationale below). +provided). This is safe only for sources that are not cross-compiled and +therefore it is NOT the default value (see rationale below). #### `Scala2` -Use `_` as wildcard and `=>` for renames. +Use `_` as wildcard and `=>` for renames. Curly braces are striped for importers +with a single regular or wildcard importee. #### `Scala3` -Use `*` as wildcard and `as` for renames. +Use `*` as wildcard and `as` for renames. Curly braces are striped for importers +with a single importee. ### Default value @@ -1374,11 +1376,16 @@ OrganizeImports { Before: ```scala +import scala.collection.immutable.{List => L} +import scala.collection.mutable.{Map, Buffer => _, Seq => S, _} ``` After: ```scala +import scala.collection.immutable.{List => L} +import scala.collection.mutable.Map +import scala.collection.mutable.{Buffer => _, Seq => S, _} ``` #### `Scala3` @@ -1392,10 +1399,17 @@ OrganizeImports { Before: ```scala +import scala.collection.immutable.{List => L} +import scala.collection.mutable.{Map, Buffer => _, Seq => S, _} +import scala.concurrent.ExecutionContext.Implicits.{given scala.concurrent.ExecutionContext} ``` After: ```scala +import scala.collection.immutable.List as L +import scala.collection.mutable.Map +import scala.collection.mutable.{Buffer as _, Seq as S, *} +import scala.concurrent.ExecutionContext.Implicits.given scala.concurrent.ExecutionContext ``` diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala index b37bd86eb5..4b4cbb8421 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala @@ -572,7 +572,12 @@ class OrganizeImports( importer match { case Importer(_, Importee.Wildcard() :: Nil) => - syntax.patch(syntax.lastIndexOfSlice("._"), ".\u0001", 2) + val wildcardSyntax = Importee.Wildcard().syntax + syntax.patch( + syntax.lastIndexOfSlice(s".$wildcardSyntax"), + ".\u0001", + 2 + ) case _ if importer.isCurlyBraced => syntax @@ -714,9 +719,66 @@ class OrganizeImports( private def importerSyntax(importer: Importer): String = importer.pos match { case pos: Position.Range => - // Position found, implies that `importer` was directly parsed from the source code. Returns - // the original parsed text to preserve the original source level formatting. - pos.text + // Position found, implies that `importer` was directly parsed from the source code. Rewrite + // importees to ensure they follow the target dialect. For importers with a single importee, + // strip enclosing braces if they exist (or add/preserve them for Rename & Unimport on Scala 2). + val syntax = new StringBuilder(pos.text) + def patchSyntax( + t: Tree, + newSyntax: String, + // None: don't touch + // Some(true): add if not there, preserve if there + // Some(false): strip if there, preserve if not there + maybeForcePresenceOrAbsenceOfBraces: Option[Boolean] = None + ) = { + val start = t.pos.start - pos.start + syntax.replace(start, t.pos.end - pos.start, newSyntax) + + maybeForcePresenceOrAbsenceOfBraces.foreach { + forcePresenceOrAbsenceOfBraces => + val end = t.pos.start - pos.start + newSyntax.length + ( + syntax.take(start).lastIndexOf('{'), + syntax.indexOf('}', end), + forcePresenceOrAbsenceOfBraces + ) match { + case (-1, -1, true) => + // braces requested but not detected + syntax.append('}') + syntax.insert(start, '{') + case (opening, closing, false) + if opening != -1 && closing != -1 => + // braces detected but not requested + println(syntax.toString() + " " + end + " " + closing) + syntax.delete(end, closing + 1) + syntax.delete(opening, start) + case _ => + } + } + } + + val Importer(_, importees) = importer + + val singleImporteeFalse = + Option + .when(importees.length == 1)(false) + val singleImporteeDialect = + Option + .when(importees.length == 1)(!targetDialect.allowAsForImportRename) + + // traverse & patch backwards to avoid shifting indices + importees.reverse.foreach { + case i @ Importee.Rename(_, _) => + patchSyntax(i, i.copy().syntax, singleImporteeDialect) + case i @ Importee.Unimport(_) => + patchSyntax(i, i.copy().syntax, singleImporteeDialect) + case i @ Importee.Wildcard() => + patchSyntax(i, i.copy().syntax, singleImporteeFalse) + case i => + patchSyntax(i, i.syntax, singleImporteeFalse) + } + + syntax.toString case Position.None => // Position not found, implies that `importer` is derived from certain existing import @@ -738,11 +800,15 @@ class OrganizeImports( implicit private class ImporterExtension(importer: Importer) { - /** Checks whether the `Importer` is curly-braced when pretty-printed. */ + /** + * Checks whether the `Importer` should be curly-braced when pretty-printed. + */ def isCurlyBraced: Boolean = { val importees @ Importees(_, renames, unimports, _, _, _) = importer.importees - renames.nonEmpty || unimports.nonEmpty || importees.length > 1 + + importees.length > 1 || + ((renames.length == 1 || unimports.length == 1) && !targetDialect.allowAsForImportRename) } /** @@ -984,7 +1050,7 @@ object OrganizeImports { * - Names, e.g., `Seq`, `Option`, etc. * - Renames, e.g., `{Long => JLong}`, `Duration as D`, etc. * - Unimports, e.g., `{Foo => _}` or `Foo as _`. - * - Givens, e.g., `{given Foo}`. + * - Givens, e.g., `given Foo`. * - GivenAll, i.e., `given`. * - Wildcard, i.e., `_` or `*`. */ diff --git a/scalafix-tests/input/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala b/scalafix-tests/input/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala new file mode 100644 index 0000000000..3c2e21066b --- /dev/null +++ b/scalafix-tests/input/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala @@ -0,0 +1,13 @@ +/* +rules = [OrganizeImports] +OrganizeImports { + removeUnused = false + targetDialect = Auto +} + */ +package test.organizeImports + +import scala.collection.immutable.{List => L} +import scala.collection.mutable._ + +object TargetDialectAuto diff --git a/scalafix-tests/input/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala b/scalafix-tests/input/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala new file mode 100644 index 0000000000..cc3408d7f9 --- /dev/null +++ b/scalafix-tests/input/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala @@ -0,0 +1,12 @@ +/* +rules = [OrganizeImports] +OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Auto + */ +package test.organizeImports + +import java.util.concurrent.{ BlockingDeque } +import java.util.concurrent.{ConcurrentHashMap} +import scala.collection.mutable.{_} + +object TargetDialectSingleImporteeStripCurlybraces diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala index 0d6a6fe0f0..0992e5f5f3 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala @@ -4,6 +4,7 @@ OrganizeImports { groupedImports = Keep coalesceToWildcardImportThreshold = 2 removeUnused = false + targetDialect = Scala3 } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala index 82e3aa7a8e..1213a38ee2 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala @@ -4,6 +4,7 @@ OrganizeImports { groupedImports = Keep coalesceToWildcardImportThreshold = 2 removeUnused = false + targetDialect = Scala3 } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala index e91fedb274..d1ba210510 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala @@ -4,6 +4,7 @@ OrganizeImports { groupedImports = Keep coalesceToWildcardImportThreshold = 2 removeUnused = false + targetDialect = Scala3 } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala index 9e374ccff5..6478767ca6 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala @@ -4,6 +4,7 @@ OrganizeImports { groupedImports = Keep coalesceToWildcardImportThreshold = 2 removeUnused = false + targetDialect = Scala3 } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala index 9005f19322..61272b74b3 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala @@ -1,6 +1,7 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandGiven.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandGiven.scala index f23f6848d0..7d15ade392 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandGiven.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandGiven.scala @@ -1,12 +1,13 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports import test.organizeImports.GivenImports.Beta import test.organizeImports.GivenImports.Alpha -import test.organizeImports.GivenImports.{given Beta, given Alpha} +import test.organizeImports.GivenImports.{given Beta, given test.organizeImports.GivenImports.Gamma, given Alpha} import scala.util.Either object ExpandGiven diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala index 457db872fa..baf2545cdc 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala @@ -1,6 +1,7 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala index f34b71897c..3fe1a6e140 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala @@ -2,18 +2,19 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports -import test.organizeImports.GivenImports._ -import test.organizeImports.GivenImports.{alpha => _, given} -import test.organizeImports.GivenImports.{given Beta} -import test.organizeImports.GivenImports.{gamma => _, given} -import test.organizeImports.GivenImports.{given Zeta} +import test.organizeImports.GivenImports.* +import test.organizeImports.GivenImports.{alpha as _, given} +import test.organizeImports.GivenImports.given Beta +import test.organizeImports.GivenImports.{gamma as _, given} +import test.organizeImports.GivenImports.given Zeta -import test.organizeImports.GivenImports2.{alpha => _} -import test.organizeImports.GivenImports2.{beta => _} -import test.organizeImports.GivenImports2.{given Gamma} -import test.organizeImports.GivenImports2.{given Zeta} +import test.organizeImports.GivenImports2.alpha as _ +import test.organizeImports.GivenImports2.beta as _ +import test.organizeImports.GivenImports2.given Gamma +import test.organizeImports.GivenImports2.given Zeta object GroupedGivenImportsMergeUnimports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala index bb0632fccd..7266c65564 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = AggressiveMerge +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeGiven.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeGiven.scala index a7d628d91b..f45028d28e 100644 --- a/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeGiven.scala +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeGiven.scala @@ -2,13 +2,15 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Scala3 */ package test.organizeImports import test.organizeImports.GivenImports.Beta import test.organizeImports.GivenImports.Alpha -import test.organizeImports.GivenImports.{given Beta} -import test.organizeImports.GivenImports.{given Alpha} +import test.organizeImports.GivenImports.given Beta +import test.organizeImports.GivenImports.given test.organizeImports.GivenImports.Gamma +import test.organizeImports.GivenImports.given Alpha import scala.util.Either object MergeGiven diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala new file mode 100644 index 0000000000..27ba4a32fe --- /dev/null +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala @@ -0,0 +1,13 @@ +/* +rules = [OrganizeImports] +OrganizeImports.removeUnused = false +OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Scala3 + */ + +package test.organizeImports + +import test.organizeImports.GivenImports.* +import test.organizeImports.GivenImports.{ given Alpha, given Beta } + +object MergeImportsFormatPreservingGiven diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala new file mode 100644 index 0000000000..df5e61c222 --- /dev/null +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala @@ -0,0 +1,11 @@ +/* +rules = [OrganizeImports] +OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Scala2 + */ +package test.organizeImports + +import scala.util.Either as E +import scala.util.Try as _ + +object TargetDialectDowngrade diff --git a/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala b/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala new file mode 100644 index 0000000000..80733c14ab --- /dev/null +++ b/scalafix-tests/input/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala @@ -0,0 +1,17 @@ +/* +rules = [OrganizeImports] +OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Auto + */ +package test.organizeImports + +import java.util.concurrent.{ BlockingDeque } +import java.util.concurrent.{ConcurrentHashMap} +import scala.collection.mutable.{*} +import scala.collection.mutable.{ListMap as _} +import scala.util.{ Try as T } + +import GivenImports.{given GivenImports.Alpha} +import GivenImports.{given} + +object TargetDialectSingleImporteeStripCurlybraces diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/AlreadyOrganized.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/AlreadyOrganized.scala index 392a2d280b..fe95cf0b33 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/AlreadyOrganized.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/AlreadyOrganized.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports @@ -9,7 +10,7 @@ import scala.collection.mutable.{ ArrayBuffer, Map, Queue, - Set + Set => S } object AlreadyOrganized diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/CoalesceImportees.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/CoalesceImportees.scala index 6a35ea974f..619c09d814 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/CoalesceImportees.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/CoalesceImportees.scala @@ -4,6 +4,7 @@ OrganizeImports { groupedImports = Keep coalesceToWildcardImportThreshold = 3 removeUnused = false + targetDialect = Auto } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala index 9f8255a677..2cdafcb7b8 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala @@ -1,10 +1,12 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Auto */ package test.organizeImports import scala.collection.{Map} +import scala.collection.{Seq => _} import scala.collection.{Set => ImmutableSet} object CurlyBracedSingleImportee diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/ExpandRelativeRootPackage.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/ExpandRelativeRootPackage.scala index 0b096c22ce..b4821e80c0 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/ExpandRelativeRootPackage.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/ExpandRelativeRootPackage.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.expandRelative = true +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala index 179b9c68a7..30bf632012 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala @@ -2,11 +2,12 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Explode +OrganizeImports.targetDialect = Auto */ package test.organizeImports import test.organizeImports.ExplodeImports.FormatPreserving.g1.{ a, b } -import test.organizeImports.ExplodeImports.FormatPreserving.g2.{ c => C, _ } +import test.organizeImports.ExplodeImports.FormatPreserving.g2.{ c => C, _ } object ExplodeImportsFormatPreserving diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala index e31c70827f..fd905e9ec3 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = AggressiveMerge +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala index 9d438645dd..5eef1dac55 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala @@ -1,6 +1,7 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala index acd497cea8..fa3c2d1efe 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala @@ -1,6 +1,7 @@ /* rules = [OrganizeImports] OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala index 15fe853fd4..a3f134859b 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala index 3a4c2cc602..283834f49a 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala index 5112136683..9b592134cb 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala index b81148506c..ff7961ab8e 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala @@ -2,6 +2,7 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderKeep.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderKeep.scala index 7e08de4d12..05bdb4ac6b 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderKeep.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderKeep.scala @@ -5,6 +5,7 @@ OrganizeImports { groupedImports = Keep importSelectorsOrder = Keep importsOrder = Keep + targetDialect = Auto } */ package test.organizeImports diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala index ee3b2db00b..cbd4fb8ef8 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala @@ -5,6 +5,7 @@ OrganizeImports { groupedImports = Keep importSelectorsOrder = Keep importsOrder = SymbolsFirst + targetDialect = Auto } */ package test.organizeImports @@ -15,6 +16,9 @@ import scala.concurrent.duration import scala.concurrent.{Promise, Future} import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.e +import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.{ e => E } +import test.organizeImports.QuotedIdent.`a.b` +import test.organizeImports.QuotedIdent.{`a.b` => ab} import test.organizeImports.QuotedIdent.`a.b`.{c => _, _} import test.organizeImports.QuotedIdent._ diff --git a/scalafix-tests/input/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala b/scalafix-tests/input/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala index 9be512c105..fa13febdc9 100644 --- a/scalafix-tests/input/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala +++ b/scalafix-tests/input/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala @@ -2,11 +2,12 @@ rules = [OrganizeImports] OrganizeImports.removeUnused = false OrganizeImports.groupedImports = Merge +OrganizeImports.targetDialect = Auto */ package test.organizeImports -import test.organizeImports.MergeImports.FormatPreserving.g1.{ a, b } +import test.organizeImports.MergeImports.FormatPreserving.g1.{ a, b => B } import test.organizeImports.MergeImports.FormatPreserving.g2._ import test.organizeImports.MergeImports.FormatPreserving.g2.{ d => D } diff --git a/scalafix-tests/output/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala b/scalafix-tests/output/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala new file mode 100644 index 0000000000..42e45c1f6f --- /dev/null +++ b/scalafix-tests/output/src/main/scala-2-xsource3/test/organizeImports/TargetDialectAuto.scala @@ -0,0 +1,6 @@ +package test.organizeImports + +import scala.collection.immutable.List as L +import scala.collection.mutable.* + +object TargetDialectAuto diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/AlreadyOrganized.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/AlreadyOrganized.scala similarity index 91% rename from scalafix-tests/output/src/main/scala/test/organizeImports/AlreadyOrganized.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/AlreadyOrganized.scala index 8c4fbc1edf..9d3b4b245d 100644 --- a/scalafix-tests/output/src/main/scala/test/organizeImports/AlreadyOrganized.scala +++ b/scalafix-tests/output/src/main/scala-2/test/organizeImports/AlreadyOrganized.scala @@ -4,7 +4,7 @@ import scala.collection.mutable.{ ArrayBuffer, Map, Queue, - Set + Set => S } object AlreadyOrganized diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/CoalesceImportees.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/CoalesceImportees.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/CoalesceImportees.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/CoalesceImportees.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/CurlyBracedSingleImportee.scala similarity index 79% rename from scalafix-tests/output/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/CurlyBracedSingleImportee.scala index 4a29962468..ad19cd09f9 100644 --- a/scalafix-tests/output/src/main/scala/test/organizeImports/CurlyBracedSingleImportee.scala +++ b/scalafix-tests/output/src/main/scala-2/test/organizeImports/CurlyBracedSingleImportee.scala @@ -1,6 +1,7 @@ package test.organizeImports import scala.collection.Map +import scala.collection.{Seq => _} import scala.collection.{Set => ImmutableSet} object CurlyBracedSingleImportee diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/ExplodeImportsFormatPreserving.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/ExplodeImportsFormatPreserving.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/ExplodeImportsFormatPreserving.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsExplodeMixed.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsExplodeMixed.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsExplodeMixed.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsExplodeUnimport.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsExplodeUnimport.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsExplodeUnimport.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeDedup.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeDedup.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeDedup.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeRenames.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeRenames.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeRenames.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeUnimports.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeUnimports.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeUnimports.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeWildcard.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/GroupedImportsMergeWildcard.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/GroupedImportsMergeWildcard.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/ImportsOrderKeep.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/ImportsOrderKeep.scala similarity index 100% rename from scalafix-tests/output/src/main/scala/test/organizeImports/ImportsOrderKeep.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/ImportsOrderKeep.scala diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/ImportsOrderSymbolsFirst.scala similarity index 69% rename from scalafix-tests/output/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/ImportsOrderSymbolsFirst.scala index 5bd3317c06..35b7e1d52d 100644 --- a/scalafix-tests/output/src/main/scala/test/organizeImports/ImportsOrderSymbolsFirst.scala +++ b/scalafix-tests/output/src/main/scala-2/test/organizeImports/ImportsOrderSymbolsFirst.scala @@ -1,7 +1,10 @@ package test.organizeImports import test.organizeImports.QuotedIdent._ +import test.organizeImports.QuotedIdent.{`a.b` => ab} +import test.organizeImports.QuotedIdent.`a.b` import test.organizeImports.QuotedIdent.`a.b`.{c => _, _} +import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.{ e => E } import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.e import scala.concurrent._ diff --git a/scalafix-tests/output/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/MergeImportsFormatPreserving.scala similarity index 96% rename from scalafix-tests/output/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala rename to scalafix-tests/output/src/main/scala-2/test/organizeImports/MergeImportsFormatPreserving.scala index dee1ea2a21..1e12198518 100644 --- a/scalafix-tests/output/src/main/scala/test/organizeImports/MergeImportsFormatPreserving.scala +++ b/scalafix-tests/output/src/main/scala-2/test/organizeImports/MergeImportsFormatPreserving.scala @@ -1,6 +1,6 @@ package test.organizeImports -import test.organizeImports.MergeImports.FormatPreserving.g1.{ a, b } +import test.organizeImports.MergeImports.FormatPreserving.g1.{ a, b => B } import test.organizeImports.MergeImports.FormatPreserving.g2._ import test.organizeImports.MergeImports.FormatPreserving.g2.{ d => D } diff --git a/scalafix-tests/output/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala b/scalafix-tests/output/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala new file mode 100644 index 0000000000..870bdd4c22 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-2/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import java.util.concurrent.BlockingDeque +import java.util.concurrent.ConcurrentHashMap +import scala.collection.mutable._ + +object TargetDialectSingleImporteeStripCurlybraces diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/AlreadyOrganized.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/AlreadyOrganized.scala new file mode 100644 index 0000000000..325ab5d2ae --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/AlreadyOrganized.scala @@ -0,0 +1,10 @@ +package test.organizeImports + +import scala.collection.mutable.{ + ArrayBuffer, + Map, + Queue, + Set as S +} + +object AlreadyOrganized diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImportees.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImportees.scala new file mode 100644 index 0000000000..51fb1f21b1 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImportees.scala @@ -0,0 +1,8 @@ +package test.organizeImports + +import scala.collection.immutable.{Map, Seq, Vector} +import scala.collection.mutable.* +import scala.concurrent.{Channel as Ch, *} +import scala.util.{Random as _, *} + +object CoalesceImportees diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala index e9530cea6c..9cd0877978 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesGivensAndNames.scala @@ -1,6 +1,6 @@ package test.organizeImports -import test.organizeImports.Givens._ -import test.organizeImports.Givens.{B => B1, C => _, _, given} +import test.organizeImports.Givens.* +import test.organizeImports.Givens.{B as B1, C as _, *, given} object CoalesceImporteesGivensAndNames diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala index b5bbceec91..851e4a8d90 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivens.scala @@ -1,5 +1,5 @@ package test.organizeImports -import test.organizeImports.Givens.{C => C1, _} +import test.organizeImports.Givens.{C as C1, *} object CoalesceImporteesNoGivens diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala index 7d44019695..e3085049c9 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoGivensNoNames.scala @@ -1,5 +1,5 @@ package test.organizeImports -import test.organizeImports.Givens.{A => A1, B => _, _} +import test.organizeImports.Givens.{A as A1, B as _, *} object CoalesceImporteesNoGivensNoNames diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala index c6a2d29400..147685d254 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CoalesceImporteesNoNames.scala @@ -1,6 +1,6 @@ package test.organizeImports -import test.organizeImports.Givens._ -import test.organizeImports.Givens.{A => A1, given} +import test.organizeImports.Givens.* +import test.organizeImports.Givens.{A as A1, given} object CoalesceImporteesNoNames diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/CurlyBracedSingleImportee.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CurlyBracedSingleImportee.scala new file mode 100644 index 0000000000..bc8afbc51f --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/CurlyBracedSingleImportee.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import scala.collection.Map +import scala.collection.Seq as _ +import scala.collection.Set as ImmutableSet + +object CurlyBracedSingleImportee diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala index 67b6cb5c4e..7ce77bd267 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/DeduplicateGivenImportees.scala @@ -1,6 +1,6 @@ package test.organizeImports -import test.organizeImports.Givens._ +import test.organizeImports.Givens.* import test.organizeImports.Givens.given A import test.organizeImports.Givens.given B import test.organizeImports.Givens.given C diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandGiven.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandGiven.scala index e5e028ac85..d14eafbf15 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandGiven.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandGiven.scala @@ -4,6 +4,7 @@ import test.organizeImports.GivenImports.Alpha import test.organizeImports.GivenImports.Beta import test.organizeImports.GivenImports.given Alpha import test.organizeImports.GivenImports.given Beta +import test.organizeImports.GivenImports.given test.organizeImports.GivenImports.Gamma import scala.util.Either diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala index 132be5915a..df538e1813 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExpandUnimportGiven.scala @@ -2,9 +2,9 @@ package test.organizeImports import test.organizeImports.GivenImports.Alpha import test.organizeImports.GivenImports.Beta +import test.organizeImports.GivenImports.alpha as _ import test.organizeImports.GivenImports.given Alpha -import test.organizeImports.GivenImports.{alpha => _} -import test.organizeImports.GivenImports.{beta => _, given} +import test.organizeImports.GivenImports.{beta as _, given} import scala.util.Either diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExplodeImportsFormatPreserving.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExplodeImportsFormatPreserving.scala new file mode 100644 index 0000000000..8d5d0fc472 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ExplodeImportsFormatPreserving.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import test.organizeImports.ExplodeImports.FormatPreserving.g1.a +import test.organizeImports.ExplodeImports.FormatPreserving.g1.b +import test.organizeImports.ExplodeImports.FormatPreserving.g2.{ c as C, * } + +object ExplodeImportsFormatPreserving diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala index 4a1a27b267..a6856a8d8d 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedGivenImportsMergeUnimports.scala @@ -1,8 +1,8 @@ package test.organizeImports -import test.organizeImports.GivenImports._ -import test.organizeImports.GivenImports.{gamma => _, given Beta, given Zeta, given} -import test.organizeImports.GivenImports2.{alpha => _, beta => _} +import test.organizeImports.GivenImports.* +import test.organizeImports.GivenImports.{gamma as _, given Beta, given Zeta, given} +import test.organizeImports.GivenImports2.{alpha as _, beta as _} import test.organizeImports.GivenImports2.{given Gamma, given Zeta} object GroupedGivenImportsMergeUnimports diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala index 2c5436cc02..a6be3f3f7b 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeGivenAll.scala @@ -1,10 +1,10 @@ package test.organizeImports -import test.organizeImports.GivenImports._ +import test.organizeImports.GivenImports.* import test.organizeImports.GivenImports.given -import test.organizeImports.MergeImports.Wildcard1._ -import test.organizeImports.MergeImports.Wildcard1.{b => B} -import test.organizeImports.MergeImports.Wildcard2._ +import test.organizeImports.MergeImports.Wildcard1.* +import test.organizeImports.MergeImports.Wildcard1.b as B +import test.organizeImports.MergeImports.Wildcard2.* object GroupedImportsAggressiveMergeGivenAll diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala new file mode 100644 index 0000000000..c8e490dd3a --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsAggressiveMergeWildcard.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.Wildcard1.* +import test.organizeImports.MergeImports.Wildcard1.b as B +import test.organizeImports.MergeImports.Wildcard2.* + +object GroupedImportsAggressiveMergeWildcard diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeMixed.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeMixed.scala new file mode 100644 index 0000000000..8e46fb80a9 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeMixed.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import scala.collection.immutable.* +import scala.collection.mutable.Map +import scala.collection.mutable.{Buffer as _, Seq as S, *} + +object GroupedImportsExplodeMixed diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeUnimport.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeUnimport.scala new file mode 100644 index 0000000000..777a49fdd0 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsExplodeUnimport.scala @@ -0,0 +1,5 @@ +package test.organizeImports + +import scala.collection.{Seq as _, *} + +object GroupedImportExplodeUnimport diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeDedup.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeDedup.scala new file mode 100644 index 0000000000..ce51ff68f0 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeDedup.scala @@ -0,0 +1,5 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.Dedup.{a, b as b1, c as _} + +object GroupedImportsMergeDedup diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeRenames.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeRenames.scala new file mode 100644 index 0000000000..d50ab9199a --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeRenames.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.Rename1.{a as A, b as B, c, d} +import test.organizeImports.MergeImports.Rename2.{a as A, b as B, c} +import test.organizeImports.MergeImports.Rename2.{a, b} + +object GroupedImportsMergeRenames diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeUnimports.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeUnimports.scala new file mode 100644 index 0000000000..27cb850b09 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeUnimports.scala @@ -0,0 +1,6 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.Unimport1.{b as B, c as _, d, *} +import test.organizeImports.MergeImports.Unimport2.{a as _, b as _, c as C, d} + +object GroupedImportsMergeUnimports diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeWildcard.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeWildcard.scala new file mode 100644 index 0000000000..ddf2795236 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/GroupedImportsMergeWildcard.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.Wildcard1.b as B +import test.organizeImports.MergeImports.Wildcard1.{d, *} +import test.organizeImports.MergeImports.Wildcard2.{a, b, *} + +object GroupedImportsMergeWildcard diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderKeep.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderKeep.scala new file mode 100644 index 0000000000..ce414ea894 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderKeep.scala @@ -0,0 +1,12 @@ +package test.organizeImports + +import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.e +import test.organizeImports.QuotedIdent.* +import test.organizeImports.QuotedIdent.`a.b`.{c as _, *} + +import scala.concurrent.ExecutionContext.Implicits.* +import scala.concurrent.duration +import scala.concurrent.* +import scala.concurrent.{Promise, Future} + +object ImportsOrderKeep diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderSymbolsFirst.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderSymbolsFirst.scala new file mode 100644 index 0000000000..fcb1f004bb --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/ImportsOrderSymbolsFirst.scala @@ -0,0 +1,15 @@ +package test.organizeImports + +import test.organizeImports.QuotedIdent.* +import test.organizeImports.QuotedIdent.`a.b` +import test.organizeImports.QuotedIdent.`a.b` as ab +import test.organizeImports.QuotedIdent.`a.b`.{c as _, *} +import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.e +import test.organizeImports.QuotedIdent.`a.b`.`{ d }`.e as E + +import scala.concurrent.* +import scala.concurrent.{Promise, Future} +import scala.concurrent.ExecutionContext.Implicits.* +import scala.concurrent.duration + +object ImportsOrderSymbolsFirst diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeGiven.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeGiven.scala index b02b7e822c..b5230e6fd7 100644 --- a/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeGiven.scala +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeGiven.scala @@ -1,7 +1,7 @@ package test.organizeImports import test.organizeImports.GivenImports.{Alpha, Beta} -import test.organizeImports.GivenImports.{given Alpha, given Beta} +import test.organizeImports.GivenImports.{given Alpha, given Beta, given test.organizeImports.GivenImports.Gamma} import scala.util.Either diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreserving.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreserving.scala new file mode 100644 index 0000000000..2d5352f7f3 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreserving.scala @@ -0,0 +1,7 @@ +package test.organizeImports + +import test.organizeImports.MergeImports.FormatPreserving.g1.{ a, b as B } +import test.organizeImports.MergeImports.FormatPreserving.g2.* +import test.organizeImports.MergeImports.FormatPreserving.g2.d as D + +object MergeImportsFormatPreserving diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala new file mode 100644 index 0000000000..5e1ac6bf6c --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/MergeImportsFormatPreservingGiven.scala @@ -0,0 +1,6 @@ +package test.organizeImports + +import test.organizeImports.GivenImports.* +import test.organizeImports.GivenImports.{ given Alpha, given Beta } + +object MergeImportsFormatPreservingGiven diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala new file mode 100644 index 0000000000..966f82cea1 --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectDowngrade.scala @@ -0,0 +1,6 @@ +package test.organizeImports + +import scala.util.{Either => E} +import scala.util.{Try => _} + +object TargetDialectDowngrade diff --git a/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala b/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala new file mode 100644 index 0000000000..b15308b6ce --- /dev/null +++ b/scalafix-tests/output/src/main/scala-3/test/organizeImports/TargetDialectSingleImporteeStripCurlybraces.scala @@ -0,0 +1,12 @@ +package test.organizeImports + +import java.util.concurrent.BlockingDeque +import java.util.concurrent.ConcurrentHashMap +import scala.collection.mutable.* +import scala.collection.mutable.ListMap as _ +import scala.util.Try as T + +import GivenImports.given GivenImports.Alpha +import GivenImports.given + +object TargetDialectSingleImporteeStripCurlybraces