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

Support Scalafix migrations in Scala CLI builds #3564

Merged
merged 1 commit into from
Jan 24, 2025
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 @@ -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)
}
}
Loading