Skip to content

Commit

Permalink
Throw validation error if library uses string notation
Browse files Browse the repository at this point in the history
  • Loading branch information
pemistahl committed Jan 16, 2024
1 parent b6e8fd6 commit 9fdf8db
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
}

group = "io.github.pemistahl"
version = "1.1.0"
version = "1.0.2"

kotlin {
compilerOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class VersionCatalogLinterPluginFunctionalTest {
"Required order: [module | group], name (, version(.ref))",
"Line 2: Entry with key 'activation' in section '[libraries]' must not have " +
"two or more adjacent whitespace characters.",
"Line 4: Use table notation instead of string notation for library with key 'antlr'. " +
"Required order: [module | group], name (, version(.ref))",
"Line 7: Entries are not sorted alphabetically in section '[plugins]'. " +
"Found key 'shadowJar' where 'ktlint' was expected.",
"Line 9: Attributes of plugin with key 'ktlint' are not sorted correctly. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ abstract class VersionCatalogChecker : DefaultTask() {
for ((lineNumbers, library) in libraries) {
val parseResult = Toml.parse(library)
val key = parseResult.keySet().iterator().next()
val requiredOrder = "Required order: [module | group], name (, version(.ref))"

if (parseResult.isTable(key)) {
if (parseResult.isString(key)) {
val message =
"Use table notation instead of string notation for library with key '$key'. $requiredOrder"
errorMessages.add(ErrorMessage(lineNumbers, message))
} else if (parseResult.isTable(key)) {
val attributes = parseResult.getTable(key)!!.keySet().iterator()
val firstAttribute = attributes.next()
val secondAttribute = attributes.next()
Expand All @@ -96,8 +101,7 @@ abstract class VersionCatalogChecker : DefaultTask() {

if (!isModuleDefined && !isGroupAndNameDefined) {
val message =
"Attributes of library with key '$key' are not sorted correctly. " +
"Required order: [module | group], name (, version(.ref))"
"Attributes of library with key '$key' are not sorted correctly. $requiredOrder"
errorMessages.add(ErrorMessage(lineNumbers, message))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ class VersionCatalogCheckerTest {
).map { it.toString() },
)

assertEquals(
listOf(
"Line 1: Use table notation instead of string notation for library with key 'activation'. " +
"Required order: [module | group], name (, version(.ref))",
),
task.checkLibraries(
listOf(
1..1 to "activation = \"javax.activation:com.sun.activation:1.2.0\"",
2..2 to "antisamy = { module = \"org.owasp.antisamy:antisamy\", version.ref = \"antisamy\" }",
),
).map { it.toString() },
)

assertEquals(
listOf(
"Line 1: Attributes of library with key 'activation' are not sorted correctly. " +
Expand Down

0 comments on commit 9fdf8db

Please sign in to comment.