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

Cross-build to 2.13 #69

Merged
merged 3 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ inThisBuild(
)
),
scalaVersion := v.scala212,
crossScalaVersions := List(v.scala212, v.scala213),
scalacOptions ++= List(
"-deprecation",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this here as I fixed the deprecation warnings

"-Yrangepos",
"-P:semanticdb:synthetics:on"
),
conflictManager := ConflictManager.strict,
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",
Expand Down
27 changes: 12 additions & 15 deletions rules/src/main/scala/fix/OrganizeImports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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)) =>
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions rules/src/main/scala/fix/OrganizeImportsConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand All @@ -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
}
}

Expand Down