Skip to content

Commit

Permalink
Cross-build against 2.13.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olafur Pall Geirsson committed Sep 12, 2019
1 parent f3ceb98 commit d5d23db
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 148 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)

Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -127,7 +135,7 @@ lazy val testsOutput = project
noPublish,
semanticdbSettings,
scalacOptions --= List(
warnUnusedImports,
warnUnusedImports.value,
"-Xlint"
),
testsInputOutputSetting,
Expand Down
23 changes: 11 additions & 12 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)

Expand Down
37 changes: 24 additions & 13 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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" ::
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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"
57 changes: 29 additions & 28 deletions scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions scalafix-core/src/main/scala-2.11/scalafix/util/Compat.scala
Original file line number Diff line number Diff line change
@@ -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]]
}
8 changes: 8 additions & 0 deletions scalafix-core/src/main/scala-2.12/scalafix/util/Compat.scala
Original file line number Diff line number Diff line change
@@ -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]]
}
6 changes: 6 additions & 0 deletions scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scalafix.util

object Compat {
type View[T] = collection.View[T]
type SeqView[T] = collection.SeqView[T]
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]]]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
3 changes: 3 additions & 0 deletions scalafix-core/src/main/scala/scalafix/util/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions scalafix-core/src/main/scala/scalafix/util/TokenList.scala
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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.
Expand Down Expand Up @@ -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])
}

Expand Down
Loading

0 comments on commit d5d23db

Please sign in to comment.