diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 03de17c..47905d2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: run: sbt scalafmtCheckAll "rules/scalafix --check" - name: Test - run: sbt coverage tests/test rules/coverageReport + run: sbt coverage +tests/test +rules/coverageReport - uses: codecov/codecov-action@v1 with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fcd50c1..60d45d1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,7 +11,7 @@ jobs: - uses: olafurpg/setup-scala@v2 - uses: olafurpg/setup-gpg@v2 - name: Publish ${{ github.ref }} - run: sbt scalafmtCheck "rules/scalafix --check" test ci-release + run: sbt scalafmtCheck "rules/scalafix --check" +test ci-release env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_SECRET: ${{ secrets.PGP_SECRET }} diff --git a/build.sbt b/build.sbt index 682e7be..939d218 100644 --- a/build.sbt +++ b/build.sbt @@ -14,7 +14,9 @@ inThisBuild( ) ), scalaVersion := v.scala212, + crossScalaVersions := List(v.scala212, v.scala213), scalacOptions ++= List( + "-deprecation", "-Yrangepos", "-P:semanticdb:synthetics:on" ), @@ -22,7 +24,8 @@ inThisBuild( dependencyOverrides ++= List( "org.scala-lang.modules" %% "scala-xml" % "1.2.0", "org.slf4j" % "slf4j-api" % "1.7.25", - "com.lihaoyi" %% "sourcecode" % "0.2.1" + "com.lihaoyi" %% "sourcecode" % "0.2.1", + "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.6" ), addCompilerPlugin(scalafixSemanticdb), scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.3.1-RC2", diff --git a/rules/src/main/scala/fix/OrganizeImports.scala b/rules/src/main/scala/fix/OrganizeImports.scala index 3fc0e00..16c44aa 100644 --- a/rules/src/main/scala/fix/OrganizeImports.scala +++ b/rules/src/main/scala/fix/OrganizeImports.scala @@ -228,16 +228,15 @@ class OrganizeImports(config: OrganizeImportsConfig) extends SemanticRule("Organ else importer.copy(ref = toRef(importer.ref.symbol)) } - private def groupImporters(importers: Seq[Importer]): Seq[Seq[Importer]] = { - val (_, importerGroups) = importers + private def groupImporters(importers: Seq[Importer]): Seq[Seq[Importer]] = + importers .groupBy(matchImportGroup) // Groups imports by importer prefix. - .mapValues(organizeImportGroup) // Organize imports within the same group. .toSeq .sortBy { case (index, _) => index } // Sorts import groups by group index - .unzip - - importerGroups - } + .map { + // Organize imports within the same group. + case (_, importers) => organizeImportGroup(importers) + } private def organizeImportGroup(importers: Seq[Importer]): Seq[Importer] = { val importeesSorted = { @@ -261,12 +260,12 @@ class OrganizeImports(config: OrganizeImportsConfig) extends SemanticRule("Organ importer match { case Importer(_, Importee.Wildcard() :: Nil) => - syntax.patch(syntax.lastIndexOfSlice("._"), ".\0", 2) + syntax.patch(syntax.lastIndexOfSlice("._"), ".\u0000", 2) case _ if isCurlyBraced(importer) => syntax - .replaceFirst("[{]", "\2") - .patch(syntax.lastIndexOf("}"), "\2", 1) + .replaceFirst("[{]", "\u0002") + .patch(syntax.lastIndexOf("}"), "\u0002", 1) case _ => syntax } @@ -442,8 +441,7 @@ object OrganizeImports { val allRenames = allImportees .filter(_.is[Importee.Rename]) .groupBy { case Importee.Rename(Name(name), _) => name } - .mapValues(_.head) - .values + .map { case (_, importees) => importees.head } .toList // Collects distinct explicitly imported names, and filters out those that are also renamed. @@ -464,8 +462,7 @@ object OrganizeImports { val (renamedNames, importedNames) = allImportees .filter(_.is[Importee.Name]) .groupBy { case Importee.Name(Name(name)) => name } - .mapValues(_.head) - .values + .map { case (_, importees) => importees.head } .toList .partition { case Importee.Name(Name(name)) => @@ -598,7 +595,7 @@ object OrganizeImports { importGroups .map(prettyPrintImportGroup) .mkString("\n\n") - .lines + .linesIterator .zipWithIndex .map { // The first line will be inserted at an already indented position. diff --git a/rules/src/main/scala/fix/OrganizeImportsConfig.scala b/rules/src/main/scala/fix/OrganizeImportsConfig.scala index b8e0fd7..88c55f5 100644 --- a/rules/src/main/scala/fix/OrganizeImportsConfig.scala +++ b/rules/src/main/scala/fix/OrganizeImportsConfig.scala @@ -14,9 +14,9 @@ object ImportsOrder { case object Keep extends ImportsOrder implicit def reader: ConfDecoder[ImportsOrder] = - ReaderUtil.fromMap { - List(Ascii, SymbolsFirst, Keep) groupBy (_.toString) mapValues (_.head) - } + ReaderUtil.fromMap( + (List(Ascii, SymbolsFirst, Keep) map (v => v.toString -> v)).toMap + ) } sealed trait ImportSelectorsOrder @@ -28,7 +28,7 @@ object ImportSelectorsOrder { implicit def reader: ConfDecoder[ImportSelectorsOrder] = ReaderUtil.fromMap { - List(Ascii, SymbolsFirst, Keep) groupBy (_.toString) mapValues (_.head) + (List(Ascii, SymbolsFirst, Keep) map (v => v.toString -> v)).toMap } } @@ -41,7 +41,7 @@ object GroupedImports { implicit def reader: ConfDecoder[GroupedImports] = ReaderUtil.fromMap { - List(Merge, Explode, Keep) groupBy (_.toString) mapValues (_.head) + (List(Merge, Explode, Keep) map (v => v.toString -> v)).toMap } }