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

Issue:
"Unable to bump version" when version is defined as both a string and a val
The great work in #2816 resolved most of the "Unable to bump version" errors that I've seen on internal projects. However, I did find one new one.

The build setup looks like this:

```scala
val FooLibrariesVersion = "1.2.3"

libraryDependencies ++= Seq(
 "com.foo" %% "library-1" % FooLibrariesVersion,
 "com.foo" %% "library-2" % FooLibrariesVersion,
 "com.foo" %% "library-3" % FooLibrariesVersion,
 "com.foo" %% "library-4" % "0.1.2"
)
```

The latest version of all four dependencies is "2.0.0".

Here's what scala-steward does:

1. recognizes that `"library-1", "library-2", "library-3", "library-4"` all need to be bumped to `"2.0.0"` as well ("Found 4 updates")
2. fails to bump `"library-1", "library-2", "library-3"` ("Unable to bump version")
3. correctly bumps `"library-4"` to `"2.0.0"`


I've changed the library names and versions, but everything should still map to reality.

I suspect that consolidating the versions to a single val will fix things, but this still seems like it's worth reporting.

Can someone point me to a way to test out this specific scenario w/ the current heuristics implementation? Maybe I can take a pass at fixing this.

Pull request:
This is a fix and tests for the issue I raised in #2877.

Prior to this fix, scala-steward was failing to properly update this example:

```scala
val ScalaTestVersion = "3.2.13"
libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % ScalaTestVersion,
  "org.scalatest" %% "scalactic" % "3.2.13"
)
````

due to the trailing comma in `ScalaTestVersion,`.

Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/edit/update/data/ModulePosition.scala b/modules/core/src/main/scala/org/scalasteward/core/edit/update/data/ModulePosition.scala
index c28f1b6b06..93bd5d11cf 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/edit/update/data/ModulePosition.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/edit/update/data/ModulePosition.scala
@@ -29,5 +29,5 @@ final case class ModulePosition(
     version: Substring.Position
 ) {
   def unwrappedVersion: String =
-    version.value.dropWhile(Set('"', '$', '{')).reverse.dropWhile(Set('"', '}')).reverse
+    version.value.dropWhile(Set('"', '$', '{')).reverse.dropWhile(Set('"', '}', ',')).reverse
 }


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 1b65100448..d049215416 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
@@ -840,6 +840,58 @@ class RewriteTest extends FunSuite {
     runApplyUpdate(update, original, expected)
   }
 
+  test("issue-2877: sbt using same version in a val and a literal using a Seq addition") {
+    val update = ("org.scalatest".g % Nel.of(
+      "scalatest".a,
+      "scalactic".a
+    ) % "3.2.13" %> "3.2.14").group
+    val original = Map(
+      "build.sbt" ->
+        """
+          |val ScalaTestVersion = "3.2.13"
+          |libraryDependencies ++= Seq(
+          |  "org.scalatest" %% "scalatest" % ScalaTestVersion,
+          |  "org.scalatest" %% "scalactic" % "3.2.13"
+          |)
+          |""".stripMargin
+    )
+    val expected = Map(
+      "build.sbt" ->
+        """
+          |val ScalaTestVersion = "3.2.14"
+          |libraryDependencies ++= Seq(
+          |  "org.scalatest" %% "scalatest" % ScalaTestVersion,
+          |  "org.scalatest" %% "scalactic" % "3.2.14"
+          |)
+          |""".stripMargin
+    )
+    runApplyUpdate(update, original, expected)
+  }
+
+  test("issue-2877: sbt using same version in a val and a literal using individual additions") {
+    val update = ("org.scalatest".g % Nel.of(
+      "scalatest".a,
+      "scalactic".a
+    ) % "3.2.13" %> "3.2.14").group
+    val original = Map(
+      "build.sbt" ->
+        """
+          |val ScalaTestVersion = "3.2.13"
+          |libraryDependencies += "org.scalatest" %% "scalatest" % ScalaTestVersion
+          |libraryDependencies += "org.scalatest" %% "scalactic" % "3.2.13"
+          |""".stripMargin
+    )
+    val expected = Map(
+      "build.sbt" ->
+        """
+          |val ScalaTestVersion = "3.2.14"
+          |libraryDependencies += "org.scalatest" %% "scalatest" % ScalaTestVersion
+          |libraryDependencies += "org.scalatest" %% "scalactic" % "3.2.14"
+          |""".stripMargin
+    )
+    runApplyUpdate(update, original, expected)
+  }
+
   private def runApplyUpdate(
       update: Update.Single,
       files: Map[String, String],