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

scalafix 0.13.0 #6807

Merged
merged 2 commits into from
Oct 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case class ScalafixProvider(
buildHasErrors: AbsolutePath => Boolean,
)(implicit ec: ExecutionContext, rc: ReportContext) {
import ScalafixProvider._
private val scalafixCache = TrieMap.empty[ScalaBinaryVersion, Scalafix]
private val scalafixCache = TrieMap.empty[ScalaVersion, Scalafix]
private val rulesClassloaderCache =
TrieMap.empty[ScalafixRulesClasspathKey, URLClassLoader]

Expand Down Expand Up @@ -242,6 +242,8 @@ case class ScalafixProvider(
|OrganizeImports.removeUnused = true
|OrganizeImports.targetDialect = Scala3
|
|ExplicitResultTypes.fetchScala3CompilerArtifactsOnVersionMismatch = true
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Users of ExplicitResultTypes will most likely have a custom cone anyway, but I guess it doesn't hurt to put it there

|
|""".stripMargin
)
path.toFile().deleteOnExit()
Expand All @@ -257,6 +259,8 @@ case class ScalafixProvider(
|OrganizeImports.removeUnused = false
|OrganizeImports.targetDialect = Scala3
|
|ExplicitResultTypes.fetchScala3CompilerArtifactsOnVersionMismatch = true
|
|""".stripMargin
)
path.toFile().deleteOnExit()
Expand Down Expand Up @@ -379,7 +383,7 @@ case class ScalafixProvider(
}

val result = for {
api <- getScalafix(scalaBinaryVersion)
api <- getScalafix(scalaTarget.scalaVersion)
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

@bjaglin bjaglin Sep 27, 2024

Choose a reason for hiding this comment

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

Keeping 2.13 by default for community rules via

val scalaBinaryVersion =
if (isScala3) "2.13" else scalaTarget.scalaBinaryVersion
as they can be loaded by cli_3 and we haven't started cross-building rules to Scala 3 (apart from the built-in ones)

urlClassLoaderWithExternalRule <- getRuleClassLoader(
scalafixRulesKey,
api.getClass.getClassLoader,
Expand Down Expand Up @@ -484,7 +488,8 @@ case class ScalafixProvider(
val isScala3Dialect = isScala3 || isScalaSource
val canRemoveUnused = !isScala3 ||
// https://github.com/scala/scala3/pull/17835
Seq("3.0", "3.1", "3.2", "3.3")
// https://github.com/scala/scala3/pull/20315
Seq("3.0", "3.1", "3.2", "3.3.0", "3.3.1", "3.3.2", "3.3.3")
.forall(v => !scalaVersion.startsWith(v))
val confFile = scalafixConf(isScala3Dialect, canRemoveUnused)
confFile match {
Expand Down Expand Up @@ -569,15 +574,15 @@ case class ScalafixProvider(
}

private def getScalafix(
scalaBinaryVersion: ScalaBinaryVersion
scalaVersion: ScalaVersion
): Future[Scalafix] = Future {
scalafixCache.getOrElseUpdate(
scalaBinaryVersion, {
scalaVersion, {
workDoneProgress.trackBlocking("Downloading scalafix") {
val scalafix =
if (scalaBinaryVersion == "2.11") scala211Fallback
if (scalaVersion.startsWith("2.11")) scala211Fallback
else
Scalafix.fetchAndClassloadInstance(scalaBinaryVersion)
Scalafix.fetchAndClassloadInstance(scalaVersion)
scalafix
}
},
Expand Down Expand Up @@ -613,11 +618,11 @@ case class ScalafixProvider(
val rulesDependencies = scalfixRulesKey.usedRulesWithClasspath
val organizeImportRule =
// Scalafix version that supports Scala 2.11 doesn't have the rule built in
if (scalfixRulesKey.scalaBinaryVersion == "2.11")
if (scalfixRulesKey.scalaVersion.startsWith("2.11"))
Some(
Dependency.of(
"com.github.liancheng",
"organize-imports_" + scalfixRulesKey.scalaBinaryVersion,
"organize-imports_2.11",
"0.6.0",
)
)
Expand Down Expand Up @@ -677,11 +682,10 @@ case class ScalafixProvider(

object ScalafixProvider {

type ScalaBinaryVersion = String
type ScalaVersion = String

case class ScalafixRulesClasspathKey(
scalaBinaryVersion: ScalaBinaryVersion,
scalaVersion: ScalaVersion,
usedRulesWithClasspath: Set[Dependency],
)

Expand Down
2 changes: 1 addition & 1 deletion project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object V {
val sbtBloop = bloop
val sbtJdiTools = "1.1.1"
val scalaCli = "1.5.0"
val scalafix = "0.12.1"
val scalafix = "0.13.0"
val scalafmt = "3.7.15"
val scalameta = "4.9.9"
val scribe = "3.15.0"
Expand Down
Loading