Skip to content

Commit

Permalink
Fixed support for ktlint plain reporter (#376)
Browse files Browse the repository at this point in the history
Was throwing error `Invalid color parameter`

Fix: resolves #359
  • Loading branch information
freemanjp committed Mar 14, 2021
1 parent 877d6e8 commit 9764bc9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-core</artifactId>
</dependency>
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-reporter-plain</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -349,11 +353,6 @@
<artifactId>ktlint-reporter-json</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-reporter-plain</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-ruleset-experimental</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.github.gantsign.maven.plugin.ktlint

import com.github.gantsign.maven.plugin.ktlint.internal.Check
import com.github.gantsign.maven.plugin.ktlint.internal.Sources
import com.pinterest.ktlint.reporter.plain.internal.Color
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets.UTF_8
import org.apache.maven.plugins.annotations.LifecyclePhase
Expand All @@ -53,6 +54,18 @@ class CheckMojo : AbstractBaseMojo() {
@Parameter
private var reporters: Set<ReporterConfig>? = null

/**
* Whether the KtLint reporter should output in color (doesn't affect the Maven output).
*/
@Parameter
private var reporterColor: Boolean = false

/**
* The color the KtLint reporter should output in (doesn't affect the Maven output).
*/
@Parameter
private var reporterColorName: String = Color.DARK_GRAY.name

/**
* Show error codes.
*/
Expand Down Expand Up @@ -105,6 +118,8 @@ class CheckMojo : AbstractBaseMojo() {
android = android,
reporterConfig = reporters ?: emptySet(),
verbose = verbose,
reporterColor = reporterColor,
reporterColorName = reporterColorName,
enableExperimentalRules = experimental,
failOnViolation = failOnViolation
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ internal abstract class AbstractCheckSupport(
android: Boolean,
private val reporterConfig: Set<ReporterConfig>,
protected val verbose: Boolean,
private var reporterColor: Boolean,
private var reporterColorName: String,
enableExperimentalRules: Boolean
) : AbstractLintSupport(log, basedir, android, enableExperimentalRules) {

Expand Down Expand Up @@ -79,7 +81,9 @@ internal abstract class AbstractCheckSupport(
ReporterTemplate(
id = reporterId,
config = mapOf(
"verbose" to verbose.toString()
"verbose" to verbose.toString(),
"color" to reporterColor.toString(),
"color_name" to reporterColorName
) + properties,
output = output?.toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ internal class Check(
android: Boolean,
reporterConfig: Set<ReporterConfig>,
verbose: Boolean,
reporterColor: Boolean,
reporterColorName: String,
enableExperimentalRules: Boolean,
private val failOnViolation: Boolean
) : AbstractCheckSupport(
Expand All @@ -51,6 +53,8 @@ internal class Check(
android,
addMavenReporter(reporterConfig),
verbose,
reporterColor,
reporterColorName,
enableExperimentalRules
) {
operator fun invoke() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.github.gantsign.maven.plugin.ktlint.internal

import com.github.gantsign.maven.plugin.ktlint.ReporterConfig
import com.pinterest.ktlint.core.Reporter
import com.pinterest.ktlint.reporter.plain.internal.Color
import java.io.File
import java.nio.charset.Charset
import org.apache.maven.plugin.logging.Log
Expand All @@ -50,6 +51,8 @@ internal class Report(
android,
reporterConfig,
verbose,
false,
Color.DARK_GRAY.name,
enableExperimentalRules
) {
operator fun invoke(): CheckResults {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CheckMojoTest {
verify { log.debug("Discovered reporter 'plain'") }
verify { log.debug("Discovered reporter 'json'") }
verify { log.debug("Discovered reporter 'checkstyle'") }
verify { log.debug("Initializing 'maven' reporter with {verbose=false}") }
verify { log.debug("Initializing 'maven' reporter with {verbose=false, color=false, color_name=DARK_GRAY}") }
verify { log.debug("checking: src/main/kotlin/example/Example.kt") }
verify { log.debug("Style error > src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
verify { log.error("src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
Expand Down Expand Up @@ -116,7 +116,12 @@ class CheckMojoTest {
verify { log.debug("Discovered reporter 'plain'") }
verify { log.debug("Discovered reporter 'json'") }
verify { log.debug("Discovered reporter 'checkstyle'") }
verify { log.debug("Initializing 'maven' reporter with {verbose=true, group_by_file=true}") }
verify {
log.debug(
"Initializing 'maven' reporter with {verbose=true, color=false, color_name=DARK_GRAY, " +
"group_by_file=true}"
)
}
verify { log.debug("checking: src/main/kotlin/example/Example.kt") }
verify { log.debug("Style error > src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
verify { log.error("src/main/kotlin/example/Example.kt") }
Expand Down Expand Up @@ -150,7 +155,7 @@ class CheckMojoTest {
verify { log.debug("Discovered reporter 'plain'") }
verify { log.debug("Discovered reporter 'json'") }
verify { log.debug("Discovered reporter 'checkstyle'") }
verify { log.debug("Initializing 'maven' reporter with {verbose=false}") }
verify { log.debug("Initializing 'maven' reporter with {verbose=false, color=false, color_name=DARK_GRAY}") }
verify { log.debug("checking: src/main/kotlin/example/Example.kt") }
verify { log.debug("Style error > src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
verify { log.error("src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
Expand Down

0 comments on commit 9764bc9

Please sign in to comment.