Repository: scala-steward-org/scala-steward
Pull request #2239 (2021-09-21 07:38:02)

Add val for the name of the scalafmt conf file


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/io/package.scala b/modules/core/src/main/scala/org/scalasteward/core/io/package.scala
index 9229a299..70320d60 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/io/package.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/io/package.scala
@@ -19,7 +19,7 @@ package org.scalasteward.core
 import better.files.File
 import cats.syntax.all._
 import org.scalasteward.core.data.{GroupId, Update}
-import org.scalasteward.core.scalafmt.{scalafmtArtifactId, scalafmtGroupId}
+import org.scalasteward.core.scalafmt.{scalafmtArtifactId, scalafmtConfName, scalafmtGroupId}
 
 package object io {
   def isSourceFile(update: Update, fileExtensions: Set[String])(file: File): Boolean = {
@@ -32,7 +32,7 @@ package object io {
   ): Boolean =
     () match {
       case _ if isSbtUpdate(update)          => file.name === "build.properties"
-      case _ if isScalafmtCoreUpdate(update) => file.name === ".scalafmt.conf"
+      case _ if isScalafmtCoreUpdate(update) => file.name === scalafmtConfName
       case _                                 => isGenericSourceFile(file, fileExtensions)
     }
 
diff --git a/modules/core/src/main/scala/org/scalasteward/core/scalafmt/ScalafmtAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/scalafmt/ScalafmtAlg.scala
index 2580fa62..3507ebad 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/scalafmt/ScalafmtAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/scalafmt/ScalafmtAlg.scala
@@ -35,7 +35,7 @@ final class ScalafmtAlg[F[_]](config: Config)(implicit
   def getScalafmtVersion(buildRoot: BuildRoot): F[Option[Version]] =
     for {
       buildRootDir <- workspaceAlg.buildRootDir(buildRoot)
-      scalafmtConfFile = buildRootDir / ".scalafmt.conf"
+      scalafmtConfFile = buildRootDir / scalafmtConfName
       fileContent <- fileAlg.readFile(scalafmtConfFile)
     } yield fileContent.flatMap(parseScalafmtConf)
 
diff --git a/modules/core/src/main/scala/org/scalasteward/core/scalafmt/package.scala b/modules/core/src/main/scala/org/scalasteward/core/scalafmt/package.scala
index ce53c636..5079f7c0 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/scalafmt/package.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/scalafmt/package.scala
@@ -39,4 +39,6 @@ package object scalafmt {
     Dependency(scalafmtGroupIdBy(version), scalafmtArtifactId, version.value)
 
   val scalafmtBinary: String = "scalafmt"
+
+  val scalafmtConfName = ".scalafmt.conf"
 }


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/buildtool/BuildToolDispatcherTest.scala b/modules/core/src/test/scala/org/scalasteward/core/buildtool/BuildToolDispatcherTest.scala
index 0cb57c0b..aabc6228 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/buildtool/BuildToolDispatcherTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/buildtool/BuildToolDispatcherTest.scala
@@ -11,6 +11,7 @@ import org.scalasteward.core.mock.MockState
 import org.scalasteward.core.mock.MockState.TraceEntry.Cmd
 import org.scalasteward.core.repoconfig.RepoConfig
 import org.scalasteward.core.scalafmt
+import org.scalasteward.core.scalafmt.scalafmtConfName
 import org.scalasteward.core.vcs.data.Repo
 
 class BuildToolDispatcherTest extends FunSuite {
@@ -21,7 +22,7 @@ class BuildToolDispatcherTest extends FunSuite {
     val initial = MockState.empty
       .addFiles(
         repoDir / "project" / "build.properties" -> "sbt.version=1.2.6",
-        repoDir / ".scalafmt.conf" -> "version=2.0.0"
+        repoDir / scalafmtConfName -> "version=2.0.0"
       )
       .unsafeRunSync()
     val (state, deps) =
@@ -46,7 +47,7 @@ class BuildToolDispatcherTest extends FunSuite {
           s";$crossStewardDependencies;$reloadPlugins;$stewardDependencies"
         ),
         Cmd("read", s"$repoDir/project/build.properties"),
-        Cmd("read", s"$repoDir/.scalafmt.conf")
+        Cmd("read", s"$repoDir/$scalafmtConfName")
       )
     )
 
diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/EditAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/EditAlgTest.scala
index 6fd7c275..9d5dbb4e 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/edit/EditAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/edit/EditAlgTest.scala
@@ -11,7 +11,7 @@ import org.scalasteward.core.mock.MockContext.context.editAlg
 import org.scalasteward.core.mock.MockState
 import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log}
 import org.scalasteward.core.repoconfig.RepoConfig
-import org.scalasteward.core.scalafmt.scalafmtBinary
+import org.scalasteward.core.scalafmt.{scalafmtBinary, scalafmtConfName}
 import org.scalasteward.core.util.Nel
 import org.scalasteward.core.vcs.data.Repo
 
@@ -60,7 +60,7 @@ class EditAlgTest extends FunSuite {
     val data = RepoData(repo, dummyRepoCache, RepoConfig.empty)
     val repoDir = config.workspace / repo.show
     val update = Update.Single("org.scalameta" % "scalafmt-core" % "2.0.0", Nel.of("2.1.0"))
-    val scalafmtConf = repoDir / ".scalafmt.conf"
+    val scalafmtConf = repoDir / scalafmtConfName
     val scalafmtConfContent = """maxColumn = 100
                                 |version = 2.0.0
                                 |align.openParenCallSite = false
diff --git a/modules/core/src/test/scala/org/scalasteward/core/scalafmt/ScalafmtAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/scalafmt/ScalafmtAlgTest.scala
index a0bc21f4..1f00840c 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/scalafmt/ScalafmtAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/scalafmt/ScalafmtAlgTest.scala
@@ -14,7 +14,7 @@ class ScalafmtAlgTest extends FunSuite {
     val repo = Repo("fthomas", "scala-steward")
     val buildRoot = BuildRoot(repo, ".")
     val repoDir = config.workspace / repo.owner / repo.repo
-    val scalafmtConf = repoDir / ".scalafmt.conf"
+    val scalafmtConf = repoDir / scalafmtConfName
     val initialState = MockState.empty
       .addFiles(scalafmtConf -> """maxColumn = 100
                                   |version=2.0.0-RC8
@@ -24,7 +24,7 @@ class ScalafmtAlgTest extends FunSuite {
     val (state, maybeVersion) =
       scalafmtAlg.getScalafmtVersion(buildRoot).runSA(initialState).unsafeRunSync()
     val expectedState = initialState.copy(
-      trace = Vector(Cmd("read", s"$repoDir/.scalafmt.conf"))
+      trace = Vector(Cmd("read", scalafmtConf.toString))
     )
 
     assertEquals(maybeVersion, Some(Version("2.0.0-RC8")))
@@ -35,7 +35,7 @@ class ScalafmtAlgTest extends FunSuite {
     val repo = Repo("fthomas", "scala-steward")
     val buildRoot = BuildRoot(repo, ".")
     val repoDir = config.workspace / repo.owner / repo.repo
-    val scalafmtConf = repoDir / ".scalafmt.conf"
+    val scalafmtConf = repoDir / scalafmtConfName
     val initialState = MockState.empty
       .addFiles(scalafmtConf -> """maxColumn = 100
                                   |version="2.0.0-RC8"