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

Issue:
Suggest updates for Scalafix dependencies
It would be fantastic if Scala Steward could also suggest updates for `scalafixDependencies` the same way it does for `libraryDependencies`.

Is that something that would need to be implemented in the sbt-updates plugin or could it be done directly in Scala Steward?

Pull request description:
Scalafix rules given via `scalafixDependencies` are updated, too.
Scalafix rule updates are getting the label `"scalafix-rule-update"`.

Fixes #1032

Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
index 16ff70ca24..09f0cfb7a3 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
@@ -70,6 +70,8 @@ object NewPullRequestData {
     val dependencies = update.dependencies
     if (dependencies.forall(_.configurations.contains("test")))
       "test-library-update"
+    else if (dependencies.forall(_.configurations.contains("scalafix-rule")))
+      "scalafix-rule-update"
     else if (dependencies.forall(_.sbtVersion.isDefined))
       "sbt-plugin-update"
     else
diff --git a/modules/plugin/src/main/scala/org/scalasteward/plugin/StewardPlugin.scala b/modules/plugin/src/main/scala/org/scalasteward/plugin/StewardPlugin.scala
index 45b0dc2df1..0da69fa53c 100644
--- a/modules/plugin/src/main/scala/org/scalasteward/plugin/StewardPlugin.scala
+++ b/modules/plugin/src/main/scala/org/scalasteward/plugin/StewardPlugin.scala
@@ -38,10 +38,17 @@ object StewardPlugin extends AutoPlugin {
       val scalaBinaryVersionValue = scalaBinaryVersion.value
       val scalaVersionValue = scalaVersion.value
 
-      val dependencies = libraryDependencies.value
+      val libraryDeps = libraryDependencies.value
         .filter(isDefinedInBuildFiles(_, sourcePositions, buildRoot))
         .map(moduleId => toDependency(moduleId, scalaVersionValue, scalaBinaryVersionValue))
 
+      val scalafixDeps = findScalafixDependencies.value
+        .getOrElse(Seq.empty)
+        .map(moduleId =>
+          toDependency(moduleId, scalaVersionValue, scalaBinaryVersionValue, Some("scalafix-rule"))
+        )
+      val dependencies = libraryDeps ++ scalafixDeps
+
       val resolvers = fullResolvers.value.collect {
         case repo: MavenRepository if !repo.root.startsWith("file:") =>
           Resolver.MavenRepository(repo.name, repo.root)
@@ -96,6 +103,19 @@ object StewardPlugin extends AutoPlugin {
   private def isCompilerPlugin(moduleId: ModuleID): Boolean =
     moduleId.configurations.exists(_ == "plugin->default(compile)")
 
+  // base on mdoc
+  // https://github.com/scalameta/mdoc/blob/62cacfbc4c7b618228e349d4f460061916398424/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala#L164-L182
+  lazy val findScalafixDependencies: Def.Initialize[Option[Seq[ModuleID]]] = Def.settingDyn {
+    try {
+      val scalafixDependencies = SettingKey[Seq[ModuleID]]("scalafixDependencies").?
+      Def.setting {
+        scalafixDependencies.value
+      }
+    } catch {
+      case _: ClassNotFoundException => Def.setting(None)
+    }
+  }
+
   private def crossName(
       moduleId: ModuleID,
       scalaVersion: String,
@@ -106,7 +126,8 @@ object StewardPlugin extends AutoPlugin {
   private def toDependency(
       moduleId: ModuleID,
       scalaVersion: String,
-      scalaBinaryVersion: String
+      scalaBinaryVersion: String,
+      configurations: Option[String] = None
   ): Dependency =
     Dependency(
       groupId = moduleId.organization,
@@ -114,7 +135,7 @@ object StewardPlugin extends AutoPlugin {
       version = moduleId.revision,
       sbtVersion = moduleId.extraAttributes.get("e:sbtVersion"),
       scalaVersion = moduleId.extraAttributes.get("e:scalaVersion"),
-      configurations = moduleId.configurations
+      configurations = configurations.orElse(moduleId.configurations)
     )
 
   final private case class ArtifactId(


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
index f63a5fbffc..f58d68dd96 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
@@ -124,5 +124,8 @@ class NewPullRequestDataTest extends AnyFunSuite with Matchers {
     NewPullRequestData.updateType(
       Update.Single(dependency.copy(sbtVersion = Some(SbtVersion("1.0"))), Nel.of("0.2"))
     ) shouldBe "sbt-plugin-update"
+    NewPullRequestData.updateType(
+      Update.Single(dependency.copy(configurations = Some("scalafix-rule")), Nel.of("0.2"))
+    ) shouldBe "scalafix-rule-update"
   }
 }