Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 2.5.2 #104

Merged
merged 4 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "2.3.2"
version = "2.5.2"
project.git=true
align=none
align.preset=none
assumeStandardLibraryStripMargin = true
onTestFailure = "To fix this, run `./bin/scalafmt` from the project base directory"
Binary file modified bin/scalafmt
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ScalafixCompletions(

private type P = Parser[String]
private type ArgP = Parser[ShellArgs.Arg]
private type KVArgP = Parser[ArgP] // nested parser allows to match the key only
private type KVArgP =
Parser[ArgP] // nested parser allows to match the key only

private val sep: P = token("=" | " ").examples("=")
private val string: P = StringBasic
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/scalafix/internal/sbt/ScalafixCoursier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import scalafix.sbt.BuildInfo
import scala.collection.JavaConverters._

object ScalafixCoursier {
private def scalafixCliModule: Module = Module.of(
"ch.epfl.scala",
s"scalafix-cli_${BuildInfo.scala212}"
)
private def scalafixCli: Dependency = Dependency.of(
scalafixCliModule,
BuildInfo.scalafixVersion
)
private def scalafixCliModule: Module =
Module.of(
"ch.epfl.scala",
s"scalafix-cli_${BuildInfo.scala212}"
)
private def scalafixCli: Dependency =
Dependency.of(
scalafixCliModule,
BuildInfo.scalafixVersion
)

def scalafixCliJars(
repositories: Seq[cs.Repository]
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ class ScalafixInterface private (
api: ScalafixAPI,
toolClasspath: URLClassLoader,
mainCallback: ScalafixMainCallback
) = this(
api
.newArguments()
.withMainCallback(mainCallback)
.withToolClasspath(toolClasspath),
Seq(Arg.ToolClasspath(toolClasspath))
)
) =
this(
api
.newArguments()
.withMainCallback(mainCallback)
.withToolClasspath(toolClasspath),
Seq(Arg.ToolClasspath(toolClasspath))
)

// Accumulates the classpath via classloader delegation, as only the last Arg.ToolClasspath is considered
//
Expand Down
28 changes: 14 additions & 14 deletions src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ class SemanticdbNotFound(
}

s"""|The semanticdb-scalac compiler plugin is required to run semantic rules like $names.
|To fix this problem for this sbt shell session, run `scalafixEnable` and try again.
|To fix this problem permanently for your build, add the following settings to build.sbt:
|
|$recommendedSetting
|""".stripMargin
|To fix this problem for this sbt shell session, run `scalafixEnable` and try again.
|To fix this problem permanently for your build, add the following settings to build.sbt:
|
|$recommendedSetting
|""".stripMargin
}

private def atLeastSbt13(scalaVersion: String) =
s"""inThisBuild(
| List(
| scalaVersion := "$scalaVersion",
| semanticdbEnabled := true,
| semanticdbVersion := scalafixSemanticdb.revision
| )
|)
|""".stripMargin
| List(
| scalaVersion := "$scalaVersion",
| semanticdbEnabled := true,
| semanticdbVersion := scalafixSemanticdb.revision
| )
|)
|""".stripMargin

private val atMostSbt12 =
s"""addCompilerPlugin(scalafixSemanticdb)
|scalacOptions += "-Yrangepos"
|""".stripMargin
|scalacOptions += "-Yrangepos"
|""".stripMargin
}
13 changes: 7 additions & 6 deletions src/main/scala/scalafix/sbt/ScalafixEnable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ object ScalafixEnable {
briefHelp =
"Configure libraryDependencies, scalaVersion and scalacOptions for scalafix.",
detail = """1. enables the semanticdb-scalac compiler plugin
|2. sets scalaVersion to latest Scala version supported by scalafix
|3. add -Yrangepos to scalacOptions""".stripMargin
|2. sets scalaVersion to latest Scala version supported by scalafix
|3. add -Yrangepos to scalacOptions""".stripMargin
) { s =>
val extracted = Project.extract(s)
val settings: Seq[Setting[_]] = for {
(p, fullVersion) <- projectsWithMatchingScalaVersion(s)
isEnabled = libraryDependencies
.in(p)
.get(extracted.structure.data)
.exists(_.exists(_.name == "semanticdb-scalac"))
isEnabled =
libraryDependencies
.in(p)
.get(extracted.structure.data)
.exists(_.exists(_.name == "semanticdb-scalac"))
if !isEnabled
setting <- List(
scalaVersion.in(p) := fullVersion,
Expand Down
74 changes: 39 additions & 35 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ object ScalafixPlugin extends AutoPlugin {
case els =>
stdoutLogger.error(
s"""|Invalid rule: $els
|Expected format: ${DependencyRule.format}
|""".stripMargin
|Expected format: ${DependencyRule.format}
|""".stripMargin
)
throw new ScalafixFailed(List(ScalafixError.CommandLineError))
}
Expand Down Expand Up @@ -219,53 +219,57 @@ object ScalafixPlugin extends AutoPlugin {
mainInterface: ScalafixInterface,
shellArgs: ShellArgs,
config: Configuration
): Def.Initialize[Task[Unit]] = Def.task {
val files = filesToFix(shellArgs, config).value
runArgs(mainInterface.withArgs(Arg.Paths(files)), streams.value)
}
): Def.Initialize[Task[Unit]] =
Def.task {
val files = filesToFix(shellArgs, config).value
runArgs(mainInterface.withArgs(Arg.Paths(files)), streams.value)
}

private def scalafixSemantic(
ruleNames: Seq[String],
mainArgs: ScalafixInterface,
shellArgs: ShellArgs,
config: Configuration
): Def.Initialize[Task[Unit]] = Def.taskDyn {
val dependencies = allDependencies.value
val files = filesToFix(shellArgs, config).value
val withScalaInterface = mainArgs.withArgs(
Arg.ScalaVersion(scalaVersion.value),
Arg.ScalacOptions(scalacOptions.value)
)
val errors = new SemanticRuleValidator(
new SemanticdbNotFound(ruleNames, scalaVersion.value, sbtVersion.value)
).findErrors(files, dependencies, withScalaInterface)
if (errors.isEmpty) {
Def.task {
val semanticInterface = withScalaInterface.withArgs(
Arg.Paths(files),
Arg.Classpath(fullClasspath.value.map(_.data.toPath))
)
runArgs(semanticInterface, streams.value)
}
} else {
Def.task {
if (errors.length == 1) {
throw new InvalidArgument(errors.head)
} else {
val message = errors.zipWithIndex
.map { case (msg, i) => s"[E${i + 1}] $msg" }
.mkString(s"${errors.length} errors\n", "\n", "")
throw new InvalidArgument(message)
): Def.Initialize[Task[Unit]] =
Def.taskDyn {
val dependencies = allDependencies.value
val files = filesToFix(shellArgs, config).value
val withScalaInterface = mainArgs.withArgs(
Arg.ScalaVersion(scalaVersion.value),
Arg.ScalacOptions(scalacOptions.value)
)
val errors = new SemanticRuleValidator(
new SemanticdbNotFound(ruleNames, scalaVersion.value, sbtVersion.value)
).findErrors(files, dependencies, withScalaInterface)
if (errors.isEmpty) {
Def.task {
val semanticInterface = withScalaInterface.withArgs(
Arg.Paths(files),
Arg.Classpath(fullClasspath.value.map(_.data.toPath))
)
runArgs(semanticInterface, streams.value)
}
} else {
Def.task {
if (errors.length == 1) {
throw new InvalidArgument(errors.head)
} else {
val message = errors.zipWithIndex
.map { case (msg, i) => s"[E${i + 1}] $msg" }
.mkString(s"${errors.length} errors\n", "\n", "")
throw new InvalidArgument(message)
}
}
}
}
}

private def runArgs(
interface: ScalafixInterface,
streams: TaskStreams
): Unit = {
val paths = interface.args.collect { case Arg.Paths(paths) => paths }.flatten
val paths = interface.args.collect {
case Arg.Paths(paths) => paths
}.flatten
if (paths.nonEmpty) {
val cacheKeyArgs = interface.args.collect {
case cacheKey: Arg.CacheKey => cacheKey
Expand Down
57 changes: 29 additions & 28 deletions src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,34 @@ object ScalafixTestkitPlugin extends AutoPlugin {
}
import autoImport._

override def projectSettings: Seq[Def.Setting[_]] = List(
resourceGenerators.in(Test) += Def.task {
val props = new java.util.Properties()
val values = Map[String, Seq[File]](
"sourceroot" ->
List(baseDirectory.in(ThisBuild).value),
"inputClasspath" ->
scalafixTestkitInputClasspath.value.map(_.data),
"inputSourceDirectories" ->
scalafixTestkitInputSourceDirectories.value,
"outputSourceDirectories" ->
scalafixTestkitOutputSourceDirectories.value
)
values.foreach {
case (key, files) =>
props.put(
key,
files.iterator.filter(_.exists()).mkString(pathSeparator)
)
override def projectSettings: Seq[Def.Setting[_]] =
List(
resourceGenerators.in(Test) += Def.task {
val props = new java.util.Properties()
val values = Map[String, Seq[File]](
"sourceroot" ->
List(baseDirectory.in(ThisBuild).value),
"inputClasspath" ->
scalafixTestkitInputClasspath.value.map(_.data),
"inputSourceDirectories" ->
scalafixTestkitInputSourceDirectories.value,
"outputSourceDirectories" ->
scalafixTestkitOutputSourceDirectories.value
)
values.foreach {
case (key, files) =>
props.put(
key,
files.iterator.filter(_.exists()).mkString(pathSeparator)
)
}
props.put("scalaVersion", scalaVersion.value)
props.put("scalacOptions", scalacOptions.value.mkString("|"))
val out =
managedResourceDirectories.in(Test).value.head /
"scalafix-testkit.properties"
IO.write(props, "Input data for scalafix testkit", out)
List(out)
}
props.put("scalaVersion", scalaVersion.value)
props.put("scalacOptions", scalacOptions.value.mkString("|"))
val out =
managedResourceDirectories.in(Test).value.head /
"scalafix-testkit.properties"
IO.write(props, "Input data for scalafix testkit", out)
List(out)
}
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ object ScalafixTestUtility {
.map { diff =>
val msg =
s"""File: $file
|Obtained output:
|----------------
|$obtained
|Expected:
|---------
|$expected
|Diff:
|-----
|$diff""".stripMargin
|Obtained output:
|----------------
|$obtained
|Expected:
|---------
|$expected
|Diff:
|-----
|$diff""".stripMargin

streams.log.error(file)
streams.log.error(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ object ScalafixTestUtility {
.map { diff =>
val msg =
s"""File: $file
|Obtained output:
|----------------
|$obtained
|Expected:
|---------
|$expected
|Diff:
|-----
|$diff""".stripMargin
|Obtained output:
|----------------
|$obtained
|Expected:
|---------
|$expected
|Diff:
|-----
|$diff""".stripMargin

streams.log.error(file)
streams.log.error(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class LoggingOutputStreamSuite extends AnyFunSuite with Matchers {

test("capture very long messages") {
withStubLogger(Level.Warn) { (outputStream, logs) =>
val veryLongMessage = "a" * 1000000 // this would exhaust memory on quadratic implementations
val veryLongMessage =
"a" * 1000000 // this would exhaust memory on quadratic implementations
outputStream.write(s"$veryLongMessage$sep".getBytes)
logs.map(_._2) must be(mutable.Seq(veryLongMessage))
}
Expand Down
Loading