Skip to content

Commit

Permalink
Merge pull request #3564 from scala-steward-org/topic/scala-cli-scalafix
Browse files Browse the repository at this point in the history
Support Scalafix migrations in Scala CLI builds
  • Loading branch information
fthomas authored Jan 24, 2025
2 parents 6c10f0f + d1f7677 commit af9c3e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import cats.syntax.all.*
import org.scalasteward.core.buildtool.sbt.SbtAlg
import org.scalasteward.core.buildtool.{BuildRoot, BuildToolAlg}
import org.scalasteward.core.data.Scope
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.scalasteward.core.git.GitAlg
import org.scalasteward.core.io.process.SlurpOptions
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
Expand Down Expand Up @@ -91,6 +92,12 @@ final class ScalaCliAlg[F[_]](implicit
_ <- fileAlg.deleteForce(buildRootDir / exportDir)
} yield dependencies

override protected val scalafixIssue: Option[String] =
Some("https://github.com/scala-steward-org/scala-steward/issues/3486")
override def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
for {
buildRootDir <- workspaceAlg.buildRootDir(buildRoot)
cmd = Nel.of("scala-cli", "--power", "fix", "--scalafix-rules") :::
migration.rewriteRules.append(buildRootDir.pathAsString)
slurpOptions = SlurpOptions.ignoreBufferOverflow
_ <- processAlg.execSandboxed(cmd, buildRootDir, slurpOptions = slurpOptions)
} yield ()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.scalasteward.core.buildtool.sbt.command.*
import org.scalasteward.core.data.{GroupId, Repo, Version}
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.scalasteward.core.mock.MockContext.context.*
import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log}
import org.scalasteward.core.mock.MockState.TraceEntry.Cmd
import org.scalasteward.core.mock.{MockEffOps, MockState}
import org.scalasteward.core.util.Nel

Expand Down Expand Up @@ -84,8 +84,9 @@ class ScalaCliAlgTest extends CatsEffectSuite {
}

test("runMigration") {
val repo = Repo("user", "repo")
val repo = Repo("scala-cli-alg", "test-runMigration")
val buildRoot = BuildRoot(repo, ".")
val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
val migration = ScalafixMigration(
GroupId("co.fs2"),
Nel.of("fs2-core"),
Expand All @@ -94,6 +95,19 @@ class ScalaCliAlgTest extends CatsEffectSuite {
signoffCommits = None
)
val obtained = scalaCliAlg.runMigration(buildRoot, migration).runS(MockState.empty)
assertIO(obtained.map(_.trace.collect { case Log(_) => () }.size), 1)
val expected = MockState.empty.copy(trace =
Vector(
Cmd.execSandboxed(
buildRootDir,
"scala-cli",
"--power",
"fix",
"--scalafix-rules",
"github:functional-streams-for-scala/fs2/v1?sha=v1.0.5",
buildRootDir.pathAsString
)
)
)
assertIO(obtained, expected)
}
}

0 comments on commit af9c3e2

Please sign in to comment.