From 347b586e922b20eef3c4e987dc280e3b9896e463 Mon Sep 17 00:00:00 2001 From: "a.artigao" Date: Mon, 18 Nov 2024 17:15:55 +0100 Subject: [PATCH 1/3] Remove trailing comments in parsed SBT module ID --- .../edit/update/ModulePositionScanner.scala | 2 +- .../update/ModulePositionScannerTest.scala | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/org/scalasteward/core/edit/update/ModulePositionScanner.scala b/modules/core/src/main/scala/org/scalasteward/core/edit/update/ModulePositionScanner.scala index b40185724a..c6a50256b1 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/edit/update/ModulePositionScanner.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/edit/update/ModulePositionScanner.scala @@ -45,7 +45,7 @@ object ModulePositionScanner { private def sbtModuleIdRegex(dependency: Dependency): Regex = { val g = Regex.quote(dependency.groupId.value) val a = Regex.quote(dependency.artifactId.name) - raw""""($g)"\s*%+\s*"($a)"\s*%+\s*(.*)""".r + raw""""($g)"\s*%+\s*"($a)"\s*%+\s*([^\s/]*)""".r } private def findMillDependency( diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala index b440546f90..f95b41263f 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala @@ -34,6 +34,34 @@ class ModulePositionScannerTest extends FunSuite { assertEquals(obtained, expected) } + test("sbt module with version val and comment") { + val d = "org.typelevel".g % "cats-core".a % "2.9.0" + val fd = FileData("build.sbt", s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion // this is a comment""") + val obtained = ModulePositionScanner.findPositions(d, fd) + val expected = List( + ModulePosition( + Substring.Position(fd.path, 1, d.groupId.value), + Substring.Position(fd.path, 20, d.artifactId.name), + Substring.Position(fd.path, 33, "catsVersion") + ) + ) + assertEquals(obtained, expected) + } + + test("sbt module with version val and end space") { + val d = "org.typelevel".g % "cats-core".a % "2.9.0" + val fd = FileData("build.sbt", s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion """) + val obtained = ModulePositionScanner.findPositions(d, fd) + val expected = List( + ModulePosition( + Substring.Position(fd.path, 1, d.groupId.value), + Substring.Position(fd.path, 20, d.artifactId.name), + Substring.Position(fd.path, 33, "catsVersion") + ) + ) + assertEquals(obtained, expected) + } + test("sbt module where the artifactId is also part of the groupId") { val d = "com.typesafe.play".g % "play".a % "2.9.0" val fd = FileData("build.sbt", s""""com.typesafe.play" %% "play" % "2.9.0"""") From 6989f4ec4dbabff45c56c31bd44741ca64cbf803 Mon Sep 17 00:00:00 2001 From: "a.artigao" Date: Tue, 19 Nov 2024 07:00:37 +0100 Subject: [PATCH 2/3] Format files --- .../core/edit/update/ModulePositionScannerTest.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala index f95b41263f..b0d43122c7 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala @@ -36,7 +36,10 @@ class ModulePositionScannerTest extends FunSuite { test("sbt module with version val and comment") { val d = "org.typelevel".g % "cats-core".a % "2.9.0" - val fd = FileData("build.sbt", s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion // this is a comment""") + val fd = FileData( + "build.sbt", + s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion // this is a comment""" + ) val obtained = ModulePositionScanner.findPositions(d, fd) val expected = List( ModulePosition( From 5408047379c8c008153d15998d238566fcebe430 Mon Sep 17 00:00:00 2001 From: "a.artigao" Date: Tue, 19 Nov 2024 10:35:55 +0100 Subject: [PATCH 3/3] Add test for comments like `/* */` --- .../edit/update/ModulePositionScannerTest.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala index b0d43122c7..ff1b345b1c 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/edit/update/ModulePositionScannerTest.scala @@ -51,6 +51,23 @@ class ModulePositionScannerTest extends FunSuite { assertEquals(obtained, expected) } + test("sbt module with version val and comment with /* */") { + val d = "org.typelevel".g % "cats-core".a % "2.9.0" + val fd = FileData( + "build.sbt", + s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion /* this is a comment */""" + ) + val obtained = ModulePositionScanner.findPositions(d, fd) + val expected = List( + ModulePosition( + Substring.Position(fd.path, 1, d.groupId.value), + Substring.Position(fd.path, 20, d.artifactId.name), + Substring.Position(fd.path, 33, "catsVersion") + ) + ) + assertEquals(obtained, expected) + } + test("sbt module with version val and end space") { val d = "org.typelevel".g % "cats-core".a % "2.9.0" val fd = FileData("build.sbt", s""""${d.groupId}" %% "${d.artifactId.name}" % catsVersion """)