diff --git a/build.gradle.kts b/build.gradle.kts index 5d41141..525eb43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ plugins { } group = "io.github.pemistahl" -version = "1.1.0" +version = "1.0.2" kotlin { compilerOptions { diff --git a/src/functionalTest/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogLinterPluginFunctionalTest.kt b/src/functionalTest/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogLinterPluginFunctionalTest.kt index b915f18..f66fa11 100644 --- a/src/functionalTest/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogLinterPluginFunctionalTest.kt +++ b/src/functionalTest/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogLinterPluginFunctionalTest.kt @@ -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. " + diff --git a/src/main/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogChecker.kt b/src/main/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogChecker.kt index 590e2f5..0de00b4 100644 --- a/src/main/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogChecker.kt +++ b/src/main/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogChecker.kt @@ -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() @@ -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)) } } diff --git a/src/test/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogCheckerTest.kt b/src/test/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogCheckerTest.kt index a72ed4c..c9fa686 100644 --- a/src/test/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogCheckerTest.kt +++ b/src/test/kotlin/io/github/pemistahl/versioncatalog/linter/plugin/VersionCatalogCheckerTest.kt @@ -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. " +