Skip to content

Commit

Permalink
Merge pull request #419 from scalacenter/scala213
Browse files Browse the repository at this point in the history
let scalafixScalaBV follow scalaBV to leverage 2.13 & deprecate it
  • Loading branch information
bjaglin authored May 1, 2024
2 parents d21d826 + 19183af commit 84c4cd5
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 55 deletions.
26 changes: 18 additions & 8 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import sbt.*
import sbt.internal.sbtscalafix.JLineAccess
import sbt.internal.util.complete.Parser
import sbt.plugins.JvmPlugin
import sbt.librarymanagement.ResolveException
import scalafix.interfaces.{ScalafixError, ScalafixMainCallback}
import scalafix.internal.sbt.*

import scala.annotation.nowarn
import scala.collection.JavaConverters.collectionAsScalaIterableConverter
import scala.util.control.NoStackTrace
import sbt.librarymanagement.ResolveException

import scala.util.Try

object ScalafixPlugin extends AutoPlugin {
Expand Down Expand Up @@ -64,10 +64,15 @@ object ScalafixPlugin extends AutoPlugin {
"Optional list of artifacts to resolve to run custom rules. " +
"Can be set in ThisBuild or at project-level."
)
@deprecated(
"scalafixScalaBinaryVersion now follows scalaBinaryVersion by default",
"0.12.1"
)
val scalafixScalaBinaryVersion: SettingKey[String] =
settingKey[String](
"The Scala binary version used for scalafix execution. Can be set in ThisBuild or at project-level. " +
"Custom rules must be compiled against that binary version. Defaults to 2.12."
"The Scala binary version used for scalafix execution. Must be set at project-level. " +
"Custom rules must be compiled against that binary version. Defaults to 2.12 for 2.12 projects, " +
"2.13 otherwise."
)
val scalafixConfig: SettingKey[Option[File]] =
settingKey[Option[File]](
Expand Down Expand Up @@ -155,7 +160,7 @@ object ScalafixPlugin extends AutoPlugin {
loadedRules = { () =>
val scalafixInterface = ScalafixInterface(
scalafixInterfaceCache.value,
scalafixScalaBinaryVersion.value,
scalafixScalaBinaryVersion.value: @nowarn,
toolClasspath = Arg.ToolClasspath(
// Local rules classpath must be looked up via tasks so they can't appear in completions
Nil,
Expand Down Expand Up @@ -262,7 +267,13 @@ object ScalafixPlugin extends AutoPlugin {
}
},
ivyConfigurations += ScalafixConfig,
scalafixAll := scalafixAllInputTask.evaluated
scalafixAll := scalafixAllInputTask.evaluated,
(scalafixScalaBinaryVersion: @nowarn) := {
scalaBinaryVersion.value match {
case "2.12" => "2.12"
case _ => "2.13"
}
}
)

override lazy val globalSettings: Seq[Def.Setting[_]] = Seq(
Expand Down Expand Up @@ -300,7 +311,6 @@ object ScalafixPlugin extends AutoPlugin {
)
}
},
scalafixScalaBinaryVersion := "2.12",
scalafixJGitCompletion := new JGitCompletion(baseDirectory.value.toPath)
)

Expand Down Expand Up @@ -433,7 +443,7 @@ object ScalafixPlugin extends AutoPlugin {
shellArgs,
projectDepsExternal,
projectDepsInternal,
scalafixScalaBinaryVersion.value,
scalafixScalaBinaryVersion.value: @nowarn,
scalafixDependencies.value,
allResolvers,
(ThisBuild / scalafixCallback).value,
Expand Down
1 change: 0 additions & 1 deletion src/sbt-test/sbt-1.4/build-lint/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ThisBuild / scalafixDependencies := Nil
ThisBuild / scalafixResolvers := Nil
ThisBuild / scalafixScalaBinaryVersion := "2.12"
scalafixCaching := false
scalafixConfig := None
scalafixOnCompile := false
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rules = [OrganizeImports, ExplicitResultTypes]
ExplicitResultTypes.skipSimpleDefinitions = false
1 change: 1 addition & 0 deletions src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules = [OrganizeImports]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _root_.scalafix.sbt.{BuildInfo => Versions}

val scala3Version = "3.3.0"
val scala3Version = "3.4.1"
ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision

Expand All @@ -13,12 +13,11 @@ lazy val root = project
Versions.scala213,
scala3Version
),
scalacOptions ++= (if (scalaVersion.value.startsWith("2"))
Seq("-Ywarn-unused")
else Seq()),
scalafixScalaBinaryVersion := {
if (scalaBinaryVersion.value == "3") scalafixScalaBinaryVersion.value
else scalaBinaryVersion.value
scalacOptions += {
if (scalaVersion.value.startsWith("2.12"))
"-Ywarn-unused-import"
else
"-Wunused:imports"
},
scalafixConfig := {
if (scalaBinaryVersion.value == "3")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.Int

object Main {
def foo(a: Int) = a + 2.0f
}

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 1 addition & 4 deletions src/sbt-test/sbt-scalafix/local-rules/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ inThisBuild(
"ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"
),
resolvers += Resolver.sonatypeRepo("snapshots"),
scalaVersion := "2.13.11", // out of sync with scalafix.sbt.BuildInfo.scala213 on purpose
scalafixScalaBinaryVersion :=
// this should be the default in sbt-scalafix 1.0
CrossVersion.binaryScalaVersion(scalaVersion.value)
scalaVersion := "2.13.11" // out of sync with scalafix.sbt.BuildInfo.scala213 on purpose
)
)

Expand Down
10 changes: 0 additions & 10 deletions src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/build.sbt

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/test

This file was deleted.

0 comments on commit 84c4cd5

Please sign in to comment.