diff options
author | Paul Dingemans <paul-dingemans@users.noreply.github.com> | 2024-02-29 20:51:56 +0100 |
---|---|---|
committer | Paul Dingemans <paul-dingemans@users.noreply.github.com> | 2024-02-29 20:51:56 +0100 |
commit | f606b809c140b6d20296ce84004c22b611edb470 (patch) | |
tree | 79bb9a4ed116a9230de877c4e2a14d9b96d1f2dc | |
parent | b5b3697e388fe42a128b36a86852f21383012d7d (diff) | |
download | ktlint-f606b809c140b6d20296ce84004c22b611edb470.tar.gz |
Fix handling of "--reporter" CLI parameter
-rw-r--r-- | ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt | 2 | ||||
-rw-r--r-- | ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt | 60 |
2 files changed, 61 insertions, 1 deletions
diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt index 8aab056c..59d8db4f 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt @@ -165,7 +165,7 @@ internal class KtlintCommandLine : "A reporter to use (built-in: plain (default), plain?group_by_file, plain-summary, json, sarif, checkstyle, html). To use" + "a third-party reporter specify a path to a JAR file on the filesystem via ',artifact=' option. To override reporter " + "output, use ',output=' option.", - ).split(",").default(emptyList()) + ).multiple() private val rulesetJarPaths: List<String> by option( diff --git a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt index 5bd0efb6..bae6194f 100644 --- a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt +++ b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt @@ -232,6 +232,66 @@ class SimpleCLITest { } @Test + fun `Issue 2576 - single reporter`( + @TempDir + tempDir: Path, + ) { + CommandLineTestRunner(tempDir) + .run( + "too-many-empty-lines", + listOf("**/*.test", "--reporter=plain"), + ) { + SoftAssertions() + .apply { + assertErrorExitCode() + assertThat(normalOutput) + .containsLineMatching("Main.kt.test:2:1: First line in a method block should not be empty") + }.assertAll() + } + } + + @Test + fun `Issue 2576 - multiple reporters`( + @TempDir + tempDir: Path, + ) { + CommandLineTestRunner(tempDir) + .run( + "too-many-empty-lines", + listOf("**/*.test", "--reporter=plain", "--reporter=json,output=ktlint-violations.json"), + ) { + SoftAssertions() + .apply { + assertErrorExitCode() + assertThat(normalOutput) + .containsLineMatching("Initializing \"plain\" reporter") + .containsLineMatching(Regex(".*Initializing \"json\" reporter with .*, output=ktlint-violations.json")) + .containsLineMatching("Main.kt.test:2:1: First line in a method block should not be empty") + .containsLineMatching(Regex(".*ReporterAggregator -- \"json\" report written to .*ktlint-violations.json")) + }.assertAll() + } + } + + @Test + fun `Given a custom reporter which does not exist`( + @TempDir + tempDir: Path, + ) { + CommandLineTestRunner(tempDir) + .run( + "too-many-empty-lines", + listOf("**/*.test", "--reporter=custom,artifact=custom-reporter.jar"), + ) { + SoftAssertions() + .apply { + assertErrorExitCode() + assertThat(normalOutput) + .containsLineMatching("File 'custom-reporter.jar' does not exist") + }.assertAll() + } + } + + @Test fun `Generate git pre commit hook`( @TempDir tempDir: Path, |