From d5d23dbf37208533254067ddf1cea3dca6904b2b Mon Sep 17 00:00:00 2001 From: Olafur Pall Geirsson Date: Sun, 25 Aug 2019 17:04:39 -0700 Subject: [PATCH] Cross-build against 2.13. --- .travis.yml | 10 ++-- build.sbt | 18 ++++-- project/Dependencies.scala | 23 ++++---- project/ScalafixBuild.scala | 37 +++++++----- project/project/plugins.sbt | 2 +- .../scala/scalafix/internal/v1/MainOps.scala | 57 ++++++++++--------- .../scala-2.11/scalafix/util/Compat.scala | 8 +++ .../scala-2.12/scalafix/util/Compat.scala | 8 +++ .../scala-2.13/scalafix/util/Compat.scala | 6 ++ .../internal/config/ScalafixConfig.scala | 2 - .../internal/patch/ImportPatchOps.scala | 2 +- .../internal/v1/InternalSemanticDoc.scala | 6 +- .../scala/scalafix/internal/v1/package.scala | 2 - .../src/main/scala/scalafix/util/Api.scala | 3 + .../main/scala/scalafix/util/TokenList.scala | 13 ++--- .../scala/scalafix/v1/SymbolInformation.scala | 1 - .../internal/testkit/AssertDiff.scala | 12 ++-- .../scala/scalafix/testkit/TestkitPath.scala | 1 - .../test/NoUnitInsertion.scala | 0 .../src/main/scala/test/NoUnitInsertion.scala | 24 -------- .../test/LegacySyntheticsTest.scala | 0 .../src/main/resources/expect/Pretty.expect | 2 +- .../tests/cli/ScalafixImplSuite.scala | 12 ++-- .../tests/v0/LegacySyntheticsSuite.scala | 0 .../scalafix/tests/cli/CliSemanticSuite.scala | 2 +- .../tests/core/util/TokenListSuite.scala | 24 ++++---- .../tests/reflect/ToolClasspathSuite.scala | 18 ++---- .../tests/util/ScalametaStructureSuite.scala | 7 ++- 28 files changed, 152 insertions(+), 148 deletions(-) create mode 100644 scalafix-core/src/main/scala-2.11/scalafix/util/Compat.scala create mode 100644 scalafix-core/src/main/scala-2.12/scalafix/util/Compat.scala create mode 100644 scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala rename scalafix-tests/input/src/main/{scala => scala-2.12}/test/NoUnitInsertion.scala (100%) delete mode 100644 scalafix-tests/output/src/main/scala/test/NoUnitInsertion.scala rename scalafix-tests/shared/src/main/{scala => scala-2.12}/test/LegacySyntheticsTest.scala (100%) rename scalafix-tests/unit/src/test/{scala => scala-2.12}/scalafix/tests/v0/LegacySyntheticsSuite.scala (100%) diff --git a/.travis.yml b/.travis.yml index f00e4e202..597c318ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,16 @@ before_install: fi jobs: include: - - env: TEST="scalafmt" + - name: Scalafmt script: ./scalafmt --test - - env: TEST="2.11" + - name: 2.11 script: sbt ci-211 - - env: TEST="2.12" + - name: 2.12 script: sbt ci-212 + - name: 2.13 + script: sbt ci-213 - jdk: openjdk11 - env: TEST="2.12" + name: 2.12 script: sbt ci-212 # Disabled until stable v0.6 diff --git a/build.sbt b/build.sbt index bbe60ee91..3935d62ff 100644 --- a/build.sbt +++ b/build.sbt @@ -2,8 +2,8 @@ import Dependencies._ inThisBuild( List( onLoadMessage := s"Welcome to scalafix ${version.value}", - scalaVersion := "2.12.8", - crossScalaVersions := List("2.12.8", "2.11.12") + scalaVersion := scala212, + crossScalaVersions := List(scala212, scala211, scala213) ) ) @@ -29,6 +29,7 @@ lazy val interfaces = project props.put("scalametaVersion", scalametaV) props.put("scala212", scala212) props.put("scala211", scala211) + props.put("scala213", scala213) val out = managedResourceDirectories.in(Compile).value.head / "scalafix-interfaces.properties" @@ -107,14 +108,21 @@ lazy val testsShared = project coverageEnabled := false ) +val isScala213 = Def.setting(scalaVersion.value.startsWith("2.13")) + +val warnAdaptedArgs = Def.setting { + if (isScala213.value) "-Xlint:adapted-args" + else "-Ywarn-adapted-args" +} + lazy val testsInput = project .in(file("scalafix-tests/input")) .settings( noPublish, semanticdbSettings, scalacOptions ~= (_.filterNot(_ == "-Yno-adapted-args")), - scalacOptions += "-Ywarn-adapted-args", // For NoAutoTupling - scalacOptions += "-Ywarn-unused-import", // For RemoveUnusedImports + scalacOptions += warnAdaptedArgs.value, // For NoAutoTupling + scalacOptions += warnUnusedImports.value, // For RemoveUnused scalacOptions += "-Ywarn-unused", // For RemoveUnusedTerms logLevel := Level.Error, // avoid flood of compiler warnings testsInputOutputSetting, @@ -127,7 +135,7 @@ lazy val testsOutput = project noPublish, semanticdbSettings, scalacOptions --= List( - warnUnusedImports, + warnUnusedImports.value, "-Xlint" ), testsInputOutputSetting, diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 65dba0266..003798c84 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -2,12 +2,12 @@ import sbt._ /* scalafmt: { maxColumn = 120 }*/ object Dependencies { - val scalametaV = "4.2.1" - val metaconfigV = "0.9.1" - def dotty = "0.9.0-RC1" - def scala210 = "2.10.6" + val scalametaV = "4.2.3" + val metaconfigV = "0.9.4" + def scala210 = "2.10.7" def scala211 = "2.11.12" - def scala212 = "2.12.8" + def scala212 = "2.12.9" + def scala213 = "2.13.0" val currentScalaVersion = scala212 val jgit = "org.eclipse.jgit" % "org.eclipse.jgit" % "4.5.4.201711221230-r" @@ -20,17 +20,16 @@ object Dependencies { def metacp = "org.scalameta" %% "metacp" % scalametaV def semanticdbPluginLibrary = "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full def scalameta = "org.scalameta" %% "scalameta" % scalametaV - def scalatest = "org.scalatest" %% "scalatest" % "3.2.0-SNAP10" + def scalatest = "org.scalatest" %% "scalatest" % "3.0.8" def scalacheck = "org.scalacheck" %% "scalacheck" % "1.14.0" def testsDeps = List( // integration property tests - "com.geirsson" %% "coursier-small" % "1.0.0-M4", - "org.scala-lang.modules" %% "scala-xml" % "1.1.0", - "org.typelevel" %% "catalysts-platform" % "0.0.5", - "org.typelevel" %% "cats-core" % "0.9.0", - "com.typesafe.slick" %% "slick" % "3.2.0-M2", - "com.chuusai" %% "shapeless" % "2.3.2", + "io.get-coursier" %% "coursier" % "2.0.0-RC3-3", + "org.scala-lang.modules" %% "scala-xml" % "1.2.0", + "org.typelevel" %% "cats-core" % "2.0.0-RC1", + "com.typesafe.slick" %% "slick" % "3.3.2", + "com.chuusai" %% "shapeless" % "2.3.3", scalacheck ) diff --git a/project/ScalafixBuild.scala b/project/ScalafixBuild.scala index 3c4bd2a89..a076647ab 100644 --- a/project/ScalafixBuild.scala +++ b/project/ScalafixBuild.scala @@ -32,20 +32,26 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { lazy val isFullCrossVersion = Seq( crossVersion := CrossVersion.full ) - lazy val warnUnusedImports = "-Ywarn-unused-import" + lazy val isScala213 = Def.setting { + scalaVersion.value.startsWith("2.13") + } + lazy val warnUnusedImports = Def.setting { + if (isScala213.value) "-Ywarn-unused:imports" + else "-Ywarn-unused-import" + } lazy val scaladocOptions = Seq( "-groups", "-implicits" -// "-diagrams" ) - lazy val compilerOptions = Seq( - "-target:jvm-1.8", - warnUnusedImports, - "-deprecation", - "-encoding", - "UTF-8", - "-feature", - "-unchecked" + lazy val compilerOptions = Def.setting( + Seq( + "-target:jvm-1.8", + warnUnusedImports.value, + "-encoding", + "UTF-8", + "-feature", + "-unchecked" + ) ) lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq( @@ -163,9 +169,6 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { override def globalSettings: Seq[Def.Setting[_]] = List( stableVersion := version.in(ThisBuild).value.replaceFirst("\\+.*", ""), - scalacOptions ++= compilerOptions, - scalacOptions - .in(Compile, console) := compilerOptions :+ "-Yrepl-class-based", libraryDependencies ++= List( scalacheck % Test, scalatest % Test @@ -182,6 +185,11 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { "unit/test:runMain scalafix.tests.util.SaveExpect" :: s }, + commands += Command.command("ci-213") { s => + "++2.13.0" :: + "unit/test" :: + s + }, commands += Command.command("ci-212") { s => "++2.12.8" :: "unit/test" :: @@ -270,6 +278,9 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { ) override def projectSettings: Seq[Def.Setting[_]] = List( + scalacOptions ++= compilerOptions.value, + scalacOptions.in(Compile, console) := + compilerOptions.value :+ "-Yrepl-class-based", scalacOptions.in(Compile, doc) ++= scaladocOptions, publishTo := Some { if (isCustomRepository) "adhoc" at adhocRepoUri diff --git a/project/project/plugins.sbt b/project/project/plugins.sbt index 02ca208ef..b11805ec5 100644 --- a/project/project/plugins.sbt +++ b/project/project/plugins.sbt @@ -1,3 +1,3 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.23") -addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M8") +addSbtPlugin("io.get-coursier" % "sbt-coursier" % "2.0.0-RC3-3") unmanagedSources.in(Compile) += baseDirectory.value / ".." / "Dependencies.scala" diff --git a/scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala b/scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala index fb9033497..8d379aa36 100644 --- a/scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala +++ b/scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala @@ -77,37 +77,38 @@ object MainOps { } } - def files(args: ValidatedArgs): Seq[AbsolutePath] = args.args.ls match { - case Ls.Find => - val buf = ArrayBuffer.empty[AbsolutePath] - val visitor = new SimpleFileVisitor[Path] { - override def visitFile( - file: Path, - attrs: BasicFileAttributes - ): FileVisitResult = { - val path = AbsolutePath(file) - val relpath = path.toRelative(args.sourceroot) - if (args.matches(relpath)) { - buf += path + def files(args: ValidatedArgs): collection.Seq[AbsolutePath] = + args.args.ls match { + case Ls.Find => + val buf = ArrayBuffer.empty[AbsolutePath] + val visitor = new SimpleFileVisitor[Path] { + override def visitFile( + file: Path, + attrs: BasicFileAttributes + ): FileVisitResult = { + val path = AbsolutePath(file) + val relpath = path.toRelative(args.sourceroot) + if (args.matches(relpath)) { + buf += path + } + FileVisitResult.CONTINUE } - FileVisitResult.CONTINUE } - } - val roots = - if (args.args.files.isEmpty) args.sourceroot :: Nil - else args.args.files + val roots = + if (args.args.files.isEmpty) args.sourceroot :: Nil + else args.args.files - roots.foreach { root => - if (root.isFile) { - if (args.matches(root.toRelative(args.args.cwd))) { - buf += root - } - } else if (root.isDirectory) Files.walkFileTree(root.toNIO, visitor) - else args.config.reporter.error(s"$root is not a file") - } - buf.result() - } + roots.foreach { root => + if (root.isFile) { + if (args.matches(root.toRelative(args.args.cwd))) { + buf += root + } + } else if (root.isDirectory) Files.walkFileTree(root.toNIO, visitor) + else args.config.reporter.error(s"$root is not a file") + } + buf.result() + } final class StaleSemanticDB(val path: AbsolutePath, val diff: String) extends Exception(s"Stale SemanticDB\n$diff") @@ -129,7 +130,7 @@ object MainOps { def adjustExitCode( args: ValidatedArgs, code: ExitStatus, - files: Seq[AbsolutePath] + files: collection.Seq[AbsolutePath] ): ExitStatus = { if (args.callback.hasLintErrors) { ExitStatus.merge(ExitStatus.LinterError, code) diff --git a/scalafix-core/src/main/scala-2.11/scalafix/util/Compat.scala b/scalafix-core/src/main/scala-2.11/scalafix/util/Compat.scala new file mode 100644 index 000000000..2d59f0535 --- /dev/null +++ b/scalafix-core/src/main/scala-2.11/scalafix/util/Compat.scala @@ -0,0 +1,8 @@ +package scalafix.util + +import scala.collection.immutable.IndexedSeq + +object Compat { + type View[T] = collection.SeqView[T, IndexedSeq[T]] + type SeqView[T] = collection.SeqView[T, IndexedSeq[T]] +} diff --git a/scalafix-core/src/main/scala-2.12/scalafix/util/Compat.scala b/scalafix-core/src/main/scala-2.12/scalafix/util/Compat.scala new file mode 100644 index 000000000..2d59f0535 --- /dev/null +++ b/scalafix-core/src/main/scala-2.12/scalafix/util/Compat.scala @@ -0,0 +1,8 @@ +package scalafix.util + +import scala.collection.immutable.IndexedSeq + +object Compat { + type View[T] = collection.SeqView[T, IndexedSeq[T]] + type SeqView[T] = collection.SeqView[T, IndexedSeq[T]] +} diff --git a/scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala b/scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala new file mode 100644 index 000000000..a5541a3b5 --- /dev/null +++ b/scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala @@ -0,0 +1,6 @@ +package scalafix.util + +object Compat { + type View[T] = collection.View[T] + type SeqView[T] = collection.SeqView[T] +} diff --git a/scalafix-core/src/main/scala/scalafix/internal/config/ScalafixConfig.scala b/scalafix-core/src/main/scala/scalafix/internal/config/ScalafixConfig.scala index 378abd3d5..9fa9db4eb 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/config/ScalafixConfig.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/config/ScalafixConfig.scala @@ -1,8 +1,6 @@ package scalafix.internal.config import metaconfig._ -import metaconfig.Configured.Ok -import metaconfig.Configured.NotOk import metaconfig.generic.Surface import scala.meta._ import scala.meta.dialects.Scala212 diff --git a/scalafix-core/src/main/scala/scalafix/internal/patch/ImportPatchOps.scala b/scalafix-core/src/main/scala/scalafix/internal/patch/ImportPatchOps.scala index 4a11d42e1..b6abf7482 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/patch/ImportPatchOps.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/patch/ImportPatchOps.scala @@ -148,7 +148,7 @@ object ImportPatchOps { allImporters.toIterator .filter(_.importees.forall(isRemovedImportee)) .toSet - def removeSpaces(tokens: scala.Seq[Token]): Patch = { + def removeSpaces(tokens: Iterable[Token]): Patch = { tokens .takeWhile { case Token.Space() => true diff --git a/scalafix-core/src/main/scala/scalafix/internal/v1/InternalSemanticDoc.scala b/scalafix-core/src/main/scala/scalafix/internal/v1/InternalSemanticDoc.scala index 9acee47a0..48ec3495b 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/v1/InternalSemanticDoc.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/v1/InternalSemanticDoc.scala @@ -100,8 +100,8 @@ final class InternalSemanticDoc( } result } - - private[this] lazy val occurrences: util.Map[s.Range, Seq[String]] = { + private[this] lazy val occurrences + : util.Map[s.Range, collection.Seq[String]] = { val result = new util.HashMap[s.Range, ListBuffer[String]]() textDocument.occurrences.foreach { o => if (o.range.isDefined) { @@ -114,7 +114,7 @@ final class InternalSemanticDoc( buffer += o.symbol } } - result.asInstanceOf[util.Map[s.Range, Seq[String]]] + result.asInstanceOf[util.Map[s.Range, collection.Seq[String]]] } } diff --git a/scalafix-core/src/main/scala/scalafix/internal/v1/package.scala b/scalafix-core/src/main/scala/scalafix/internal/v1/package.scala index 5e9919f85..3af44cbc6 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/v1/package.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/v1/package.scala @@ -4,12 +4,10 @@ import java.net.URI import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Paths -import scala.collection.JavaConverters._ import scala.meta.inputs.Input import scala.meta.internal.io.FileIO import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath -import scala.meta.io.RelativePath package object v1 { diff --git a/scalafix-core/src/main/scala/scalafix/util/Api.scala b/scalafix-core/src/main/scala/scalafix/util/Api.scala index c65e35914..dd0924cff 100644 --- a/scalafix-core/src/main/scala/scalafix/util/Api.scala +++ b/scalafix-core/src/main/scala/scalafix/util/Api.scala @@ -28,7 +28,10 @@ trait Api { implicit class XtensionScalafixProductInspect(product: Product) { def structure: String = ProductStructure.structure(product).render(80) + @deprecated("use structureWidth instead", "0.9.7") def structure(printWidth: Int): String = + structureWidth(printWidth) + def structureWidth(printWidth: Int): String = ProductStructure.structure(product).render(printWidth) def structureLabeled: String = ProductLabeledStructure.structure(product).render(80) diff --git a/scalafix-core/src/main/scala/scalafix/util/TokenList.scala b/scalafix-core/src/main/scala/scalafix/util/TokenList.scala index 1d29cd348..0da3e4524 100644 --- a/scalafix-core/src/main/scala/scalafix/util/TokenList.scala +++ b/scalafix-core/src/main/scala/scalafix/util/TokenList.scala @@ -1,16 +1,15 @@ package scalafix.util -import scala.collection.SeqView -import scala.collection.immutable.IndexedSeq +import scalafix.util.Compat._ import scala.meta.tokens.Token import scala.meta.tokens.Tokens /** Helper to traverse tokens as a doubly linked list. */ final class TokenList private (tokens: Tokens) { - def trailing(token: Token): SeqView[Token, IndexedSeq[Token]] = + def trailing(token: Token): View[Token] = tokens.view(tok2idx(token) + 1, tokens.length) - def leading(token: Token): SeqView[Token, IndexedSeq[Token]] = + def leading(token: Token): View[Token] = tokens.view(0, tok2idx(token)).reverse private[this] val tok2idx = { @@ -30,7 +29,7 @@ final class TokenList private (tokens: Tokens) { def find(start: Token)(p: Token => Boolean): Option[Token] = tokens.drop(tok2idx(start)).find(p) - def slice(from: Token, to: Token): Seq[Token] = + def slice(from: Token, to: Token): SeqView[Token] = tokens.view(tok2idx(from), tok2idx(to)) /** Returns the next/trailing token or the original token if none exists. @@ -61,10 +60,10 @@ final class TokenList private (tokens: Tokens) { } } - def leadingSpaces(token: Token): SeqView[Token, IndexedSeq[Token]] = + def leadingSpaces(token: Token): View[Token] = leading(token).takeWhile(_.is[Token.Space]) - def trailingSpaces(token: Token): SeqView[Token, IndexedSeq[Token]] = + def trailingSpaces(token: Token): View[Token] = trailing(token).takeWhile(_.is[Token.Space]) } diff --git a/scalafix-core/src/main/scala/scalafix/v1/SymbolInformation.scala b/scalafix-core/src/main/scala/scalafix/v1/SymbolInformation.scala index 3cbc9d7e2..ba35e30ed 100644 --- a/scalafix-core/src/main/scala/scalafix/v1/SymbolInformation.scala +++ b/scalafix-core/src/main/scala/scalafix/v1/SymbolInformation.scala @@ -1,7 +1,6 @@ package scalafix.v1 import scala.meta.internal.metap.PrinterSymtab -import scala.meta.internal.semanticdb._ import scala.meta.internal.{semanticdb => s} import scala.meta.metap.Format import scalafix.internal.v1.SymbolInformationAnnotations._ diff --git a/scalafix-testkit/src/main/scala/scalafix/internal/testkit/AssertDiff.scala b/scalafix-testkit/src/main/scala/scalafix/internal/testkit/AssertDiff.scala index 9ea7d5956..79dcc0353 100644 --- a/scalafix-testkit/src/main/scala/scalafix/internal/testkit/AssertDiff.scala +++ b/scalafix-testkit/src/main/scala/scalafix/internal/testkit/AssertDiff.scala @@ -44,13 +44,11 @@ object AssertDiff { ): AssertDiff = { val data = - expectedLintMessages - .map { assert => - reportedLintMessages - .map(message => AssertDelta(assert, message)) - .to[IndexedSeq] - } - .to[IndexedSeq] + expectedLintMessages.map { assert => + reportedLintMessages + .map(message => AssertDelta(assert, message)) + .toVector + }.toVector if (reportedLintMessages.nonEmpty && expectedLintMessages.nonEmpty) { val matrix = diff --git a/scalafix-testkit/src/main/scala/scalafix/testkit/TestkitPath.scala b/scalafix-testkit/src/main/scala/scalafix/testkit/TestkitPath.scala index db5fb7102..a4a694bdc 100644 --- a/scalafix-testkit/src/main/scala/scalafix/testkit/TestkitPath.scala +++ b/scalafix-testkit/src/main/scala/scalafix/testkit/TestkitPath.scala @@ -6,7 +6,6 @@ import scala.meta.inputs.Input import scala.meta.internal.io.FileIO import scala.meta.io.AbsolutePath import scala.meta.io.RelativePath -import scalafix.internal.v1._ /** * An input file for a testkit test. diff --git a/scalafix-tests/input/src/main/scala/test/NoUnitInsertion.scala b/scalafix-tests/input/src/main/scala-2.12/test/NoUnitInsertion.scala similarity index 100% rename from scalafix-tests/input/src/main/scala/test/NoUnitInsertion.scala rename to scalafix-tests/input/src/main/scala-2.12/test/NoUnitInsertion.scala diff --git a/scalafix-tests/output/src/main/scala/test/NoUnitInsertion.scala b/scalafix-tests/output/src/main/scala/test/NoUnitInsertion.scala deleted file mode 100644 index 7d653df6c..000000000 --- a/scalafix-tests/output/src/main/scala/test/NoUnitInsertion.scala +++ /dev/null @@ -1,24 +0,0 @@ -package test - -class NoUnitInsertion { - - val x: Option[Unit] = Option(()) - - def a(u: Unit): Unit = u - a(()) - - def b(x: Int)(u: Unit): Unit = (x, u) - b(2)(()) - - val c: Unit => Unit = - u => u - c(()) - - case class Foo(u: Unit) - Foo(()) - Foo.apply(()) - - case class Bar(i: Int)(u: Unit) - Bar.apply(2)(()) - -} diff --git a/scalafix-tests/shared/src/main/scala/test/LegacySyntheticsTest.scala b/scalafix-tests/shared/src/main/scala-2.12/test/LegacySyntheticsTest.scala similarity index 100% rename from scalafix-tests/shared/src/main/scala/test/LegacySyntheticsTest.scala rename to scalafix-tests/shared/src/main/scala-2.12/test/LegacySyntheticsTest.scala diff --git a/scalafix-tests/unit/src/main/resources/expect/Pretty.expect b/scalafix-tests/unit/src/main/resources/expect/Pretty.expect index 5fcb0f030..9dda3073d 100644 --- a/scalafix-tests/unit/src/main/resources/expect/Pretty.expect +++ b/scalafix-tests/unit/src/main/resources/expect/Pretty.expect @@ -139,5 +139,5 @@ [141:15..141:21]: test/Test.Literal.string. => final val method string: "a" [142:15..142:19]: test/Test.Literal.bool. => final val method bool: true [143:15..143:19]: test/Test.Literal.unit. => final val method unit: Unit -[144:15..144:23]: test/Test.Literal.javaEnum. => final val method javaEnum +[144:15..144:23]: test/Test.Literal.javaEnum. => final val method javaEnum: NOFOLLOW_LINKS.type [145:15..145:22]: test/Test.Literal.clazzOf. => final val method clazzOf: Class[Option[Int]] \ No newline at end of file diff --git a/scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/cli/ScalafixImplSuite.scala b/scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/cli/ScalafixImplSuite.scala index cdb76b813..b3f9abc32 100644 --- a/scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/cli/ScalafixImplSuite.scala +++ b/scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/cli/ScalafixImplSuite.scala @@ -1,8 +1,5 @@ package scalafix.tests.cli -import com.geirsson.coursiersmall.CoursierSmall -import com.geirsson.coursiersmall.Dependency -import com.geirsson.coursiersmall.Settings import java.io.ByteArrayOutputStream import java.io.PrintStream import java.net.URLClassLoader @@ -12,6 +9,7 @@ import java.nio.file.Files import java.nio.file.Paths import java.util.Collections import java.util.Optional +import coursier._ import org.scalatest.FunSuite import scala.collection.JavaConverters._ import scala.meta.io.AbsolutePath @@ -127,11 +125,11 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions { Files.createDirectories(d) val semicolon = src.resolve("Semicolon.scala") val excluded = src.resolve("Excluded.scala") - val dependency = - new Dependency("com.geirsson", "example-scalafix-rule_2.12", "1.1.0") - val settings = new Settings().withDependencies(List(dependency)) // This rule is published to Maven Central to simplify testing --tool-classpath. - val toolClasspathJars = CoursierSmall.fetch(settings) + val toolClasspathJars = Fetch() + .addDependencies(dep"com.geirsson:example-scalafix-rule_2.12:1.1.0") + .run() + .toList val toolClasspath = ClasspathOps.toClassLoader( Classpath(toolClasspathJars.map(jar => AbsolutePath(jar))) ) diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/v0/LegacySyntheticsSuite.scala b/scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/v0/LegacySyntheticsSuite.scala similarity index 100% rename from scalafix-tests/unit/src/test/scala/scalafix/tests/v0/LegacySyntheticsSuite.scala rename to scalafix-tests/unit/src/test/scala-2.12/scalafix/tests/v0/LegacySyntheticsSuite.scala diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/cli/CliSemanticSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/cli/CliSemanticSuite.scala index a8fad70d7..f25b55b8c 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/cli/CliSemanticSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/cli/CliSemanticSuite.scala @@ -135,7 +135,7 @@ class CliSemanticSuite extends BaseCliSuite { "--auto-classpath", "--auto-classpath-roots", PathIO.workingDirectory.toString - ) ++ Classpaths.scalaLibrary.entries.to[Array].flatMap { path => + ) ++ Classpaths.scalaLibrary.entries.toArray.flatMap { path => Array( "--auto-classpath-roots", path.toString diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/core/util/TokenListSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/core/util/TokenListSuite.scala index a301d09fc..e58483129 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/core/util/TokenListSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/core/util/TokenListSuite.scala @@ -24,13 +24,13 @@ class TokenListSuite extends FunSuite { case _ => false } - val leading = tokenList.leading(bar) + val leading = tokenList.leading(bar).toVector assert(leading.size == 8) for ((a, b) <- tokens.zip(leading.reverse)) assert(a == b) } test("leading returns empty seq if there is no preceding tokens") { - assert(tokenList.leading(tokens.head) == Seq()) + assert(tokenList.leading(tokens.head).toList == List()) } test("leading fails if input token does not exist") { @@ -45,13 +45,13 @@ class TokenListSuite extends FunSuite { case _ => false } - val trailing = tokenList.trailing(baz) + val trailing = tokenList.trailing(baz).toVector assert(trailing.size == 11) for ((a, b) <- tokens.reverse.zip(trailing.reverse)) assert(a == b) } test("trailing returns empty seq if there is no following tokens") { - assert(tokenList.trailing(tokens.last) == Seq()) + assert(tokenList.trailing(tokens.last).toList == List()) } test("trailing fails if input token does not exist") { @@ -95,15 +95,15 @@ class TokenListSuite extends FunSuite { } test("slice returns `from` if there is no more tokens in between") { - assert(tokenList.slice(tokens.head, tokens(1)) == Seq(tokens.head)) + assert(tokenList.slice(tokens.head, tokens(1)).toList == List(tokens.head)) } test("slice returns empty seq if `from` and `to` tokens are the same object") { - assert(tokenList.slice(tokens.head, tokens.head) == Seq()) + assert(tokenList.slice(tokens.head, tokens.head).toList == List()) } test("slice returns empty seq if `from` comes after `to`") { - assert(tokenList.slice(tokens.last, tokens.head) == Seq()) + assert(tokenList.slice(tokens.last, tokens.head).toList == List()) } test("slice fails if `from` token does not exist") { @@ -124,7 +124,7 @@ class TokenListSuite extends FunSuite { val slice = tokenList.slice(kwObject, leftBrace) assert(slice.size == 4) - val Seq(kwObj, space1, bar, space2) = slice + val List(kwObj, space1, bar, space2) = slice.toList assert(kwObj == kwObject) assert(space1.is[Token.Space]) assert(bar.syntax.equals("Bar")) @@ -136,7 +136,7 @@ class TokenListSuite extends FunSuite { val spaces = tokenList.leadingSpaces(equals) assert(spaces.size == 3) - val Seq(s1, s2, s3) = spaces + val List(s1, s2, s3) = spaces.toList assert(s1 == tokenList.prev(equals)) assert(s2 == tokenList.prev(s1)) assert(s3 == tokenList.prev(s2)) @@ -147,7 +147,7 @@ class TokenListSuite extends FunSuite { ) { val Some(kwPackage) = tokens.find(_.is[Token.KwPackage]) - assert(tokenList.leadingSpaces(kwPackage) == Seq()) + assert(tokenList.leadingSpaces(kwPackage).toList == List()) } test("trailingSpaces returns all spaces following a token") { @@ -155,7 +155,7 @@ class TokenListSuite extends FunSuite { val spaces = tokenList.trailingSpaces(equals) assert(spaces.size == 3) - val Seq(s1, s2, s3) = spaces + val List(s1, s2, s3) = spaces.toList assert(s1 == tokenList.next(equals)) assert(s2 == tokenList.next(s1)) assert(s3 == tokenList.next(s2)) @@ -166,6 +166,6 @@ class TokenListSuite extends FunSuite { ) { val Some(rightBrace) = tokens.find(_.is[Token.RightBrace]) - assert(tokenList.trailingSpaces(rightBrace) == Seq()) + assert(tokenList.trailingSpaces(rightBrace).toList == List()) } } diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/reflect/ToolClasspathSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/reflect/ToolClasspathSuite.scala index df169add8..de1075e4f 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/reflect/ToolClasspathSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/reflect/ToolClasspathSuite.scala @@ -5,7 +5,7 @@ import scala.reflect.io.Directory import scala.reflect.io.PlainDirectory import scalafix.internal.reflect.RuleCompiler import scalafix.internal.tests.utils.SkipWindows -import com.geirsson.coursiersmall._ +import coursier._ import metaconfig.Conf import scala.meta.io.AbsolutePath import org.scalatest.BeforeAndAfterAll @@ -15,18 +15,10 @@ import scalafix.v1.RuleDecoder class ToolClasspathSuite extends FunSuite with BeforeAndAfterAll { var scalafmtClasspath: List[AbsolutePath] = _ override def beforeAll(): Unit = { - val scalaBinaryVersion = - scala.util.Properties.versionNumberString - .split("\\.") - .take(2) - .mkString(".") - val dependency = new Dependency( - "com.geirsson", - "scalafmt-core_" + scalaBinaryVersion, - "1.2.0" - ) - val settings = new Settings().withDependencies(List(dependency)) - val jars = CoursierSmall.fetch(settings) + val jars = Fetch() + .addDependencies(dep"com.geirsson:scalafmt-core_2.12:1.2.0") + .run() + .toList scalafmtClasspath = jars.map(AbsolutePath(_)) } diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/util/ScalametaStructureSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/util/ScalametaStructureSuite.scala index c70c71943..956746e37 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/util/ScalametaStructureSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/util/ScalametaStructureSuite.scala @@ -7,7 +7,7 @@ import scalafix.v1._ class ScalametaStructureSuite extends FunSuite with DiffAssertions { test("pretty(t)") { - val obtained = q"a.b.c.d".structure(1) + val obtained = q"a.b.c.d".structureWidth(1) val expected = """|Term.Select( | Term.Select( @@ -43,7 +43,7 @@ class ScalametaStructureSuite extends FunSuite with DiffAssertions { test("option") { assertNoDiff( - q"def foo: A = ???".decltpe.structure(1), + q"def foo: A = ???".decltpe.structureWidth(1), """| |Some(Type.Name("A")) |""".stripMargin @@ -52,7 +52,8 @@ class ScalametaStructureSuite extends FunSuite with DiffAssertions { test("list") { assertNoDiff( - q"foo(a)".args.structure(1), + // NOTE(olafur): need downcast because List is no longer a Product in 2.13. + q"foo(a)".args.asInstanceOf[Product].structureWidth(1), """|List( | Term.Name("a") |)