Repository: scala-steward-org/scala-steward (scala)

Issue:
`.scalafmt.conf` is only updated in the root directory
Scalafmt updates only change the `.scalafmt.conf` in the root directory since #2816.

before #2816:
https://github.com/fthomas/base.g8/pull/151/files

since #2816:
https://github.com/fthomas/base.g8/pull/160/files

We should restore the previous behavior and update all `.scalafmt.conf` files that use the same version.

Pull request description:
Closes #2947

Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala b/modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala
index 511e94015e..4db241d0db 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala
@@ -170,7 +170,7 @@ object Selector {
       versionPositions: List[VersionPosition]
   ): List[VersionPosition] =
     if (isMillMainUpdate(update))
-      versionPositions.filter(_.version.path === millVersionName)
+      versionPositions.filter(_.version.path.endsWith(millVersionName))
     else List.empty
 
   private def sbtVersionPositions(
@@ -188,7 +188,7 @@ object Selector {
   ): List[VersionPosition] =
     if (isScalafmtCoreUpdate(update))
       matchingSearchTerms(List("version"), versionPositions)
-        .filter(_.version.path === scalafmtConfName)
+        .filter(_.version.path.endsWith(scalafmtConfName))
     else List.empty
 
   private def moduleReplacements(


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala
index 2cf5268b89..bbfde741ea 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala
@@ -856,6 +856,15 @@ class RewriteTest extends FunSuite {
     runApplyUpdate(update, original, expected)
   }
 
+  // https://github.com/scala-steward-org/scala-steward/issues/2947
+  test(".scalafmt.conf in a subdirectory") {
+    val update =
+      ("org.scalameta".g % ("scalafmt-core", "scalafmt-core_2.12").a % "2.0.0" %> "2.0.1").single
+    val original = Map(s"foo/$scalafmtConfName" -> """version = "2.0.0" """)
+    val expected = Map(s"foo/$scalafmtConfName" -> """version = "2.0.1" """)
+    runApplyUpdate(update, original, expected)
+  }
+
   test("scalafmt.conf and other scalameta update") {
     val update = ("org.scalameta".g % "other-artifact".a % "2.0.0" %> "2.0.1").single
     val original = Map(scalafmtConfName -> """version=2.0.0""")