Skip to content

Commit

Permalink
Merge pull request #3477 from aartigao/remove-trailing-comments-val-v…
Browse files Browse the repository at this point in the history
…ersions

Remove trailing comments in parsed SBT module version
  • Loading branch information
alejandrohdezma authored Nov 19, 2024
2 parents c1e6eac + 5408047 commit 251f21e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,54 @@ 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 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 """)
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"""")
Expand Down

0 comments on commit 251f21e

Please sign in to comment.