Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing comments in parsed SBT module version #3477

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading