Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

- Log issues at `ERROR` level when `ignoreFailures = false` [#1038](https://github.com/JLLeitschuh/ktlint-gradle/pull/1038)

## [14.2.0] - 2026-03-12

- Make plugin compatible with Isolated Projects [#1032](https://github.com/JLLeitschuh/ktlint-gradle/pull/1032)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gradle.api.GradleException
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Property
import org.gradle.workers.WorkAction
Expand Down Expand Up @@ -42,14 +43,16 @@ internal abstract class ConsoleReportWorkAction : WorkAction<ConsoleReportWorkAc
}

val isLintErrorsFound = lintErrors.values.flatten().isNotEmpty()
val ignoreFailures = parameters.ignoreFailures.getOrElse(false)
if (parameters.outputToConsole.getOrElse(false) && isLintErrorsFound) {
val logLevel = if (ignoreFailures) LogLevel.WARN else LogLevel.ERROR
val verbose = parameters.verbose.get()
lintErrors.forEach { (filePath, errors) ->
errors.forEach { it.logError(filePath, verbose) }
errors.forEach { it.logError(logLevel, filePath, verbose) }
}
}

if (!parameters.ignoreFailures.getOrElse(false) && isLintErrorsFound) {
if (!ignoreFailures && isLintErrorsFound) {
val reportsPaths = parameters
.generatedReportsPaths
.files.joinToString(separator = "\n") { it.absolutePath.prefixIfNot("|- ") }
Expand All @@ -64,6 +67,7 @@ internal abstract class ConsoleReportWorkAction : WorkAction<ConsoleReportWorkAc
}

private fun SerializableLintError.logError(
logLevel: LogLevel,
filePath: String,
verbose: Boolean
) {
Expand All @@ -73,7 +77,7 @@ internal abstract class ConsoleReportWorkAction : WorkAction<ConsoleReportWorkAc
} else {
detail
}
logger.warn("$filePath:$line:$col $errorDetail$verboseSuffix")
logger.log(logLevel, "$filePath:$line:$col $errorDetail$verboseSuffix")
}

internal interface ConsoleReportParameters : WorkParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,54 @@ class KtlintPluginTest : AbstractPluginTest() {
}
}

@DisplayName("Should pass on failing sources with ignoreFailures=true")
@CommonTest
fun passOnStyleViolationWithIgnoreFailures(gradleVersion: GradleVersion) {
project(gradleVersion) {
buildGradle.appendText(
"""
ktlint.ignoreFailures = true
""".trimIndent()
)
withFailingSources()

build(CHECK_PARENT_TASK_NAME)
}
}

@DisplayName("Should log issues at \"ERROR\" level with ignoreFailures=false")
@CommonTest
fun logIssuesAtErrorLevel(gradleVersion: GradleVersion) {
project(gradleVersion) {
withFailingSources()

buildAndFail(CHECK_PARENT_TASK_NAME, "--quiet") {
assertThat(output).contains("Unnecessary long whitespace")
}
}
}

@DisplayName("Should log issues at \"WARNING\" level with ignoreFailures=true")
@CommonTest
fun logIssuesAtWarnLevelWithIgnoreFailures(gradleVersion: GradleVersion) {
project(gradleVersion) {
buildGradle.appendText(
"""
ktlint.ignoreFailures = true
""".trimIndent()
)
withFailingSources()

build(CHECK_PARENT_TASK_NAME, "--warn") {
assertThat(output).contains("Unnecessary long whitespace")
}

build(CHECK_PARENT_TASK_NAME, "--quiet", "--rerun-tasks") {
assertThat(output).doesNotContain("Unnecessary long whitespace")
}
}
}

@DisplayName("Should succeed check on clean sources")
@CommonTest
fun passCleanSources(gradleVersion: GradleVersion) {
Expand Down