Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return exit code 1 when not all errors are fixed #1868

Merged
merged 3 commits into from
Dec 18, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ interface DiktatProcessorListener {
error: DiktatError,
isCorrected: Boolean
) {
incrementAndGet()
if (!isCorrected) {
incrementAndGet()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.Paths

import kotlin.io.path.absolutePathString
import kotlin.system.exitProcess

private val log = KotlinLogging.logger { }

Expand All @@ -39,12 +40,15 @@
)

val diktatRunner = diktatRunnerFactory(diktatRunnerArguments)
when (properties.mode) {
val unfixedErrors = when (properties.mode) {
DiktatMode.CHECK -> diktatRunner.checkAll(diktatRunnerArguments)
DiktatMode.FIX -> diktatRunner.fixAll(diktatRunnerArguments) { updatedFile ->
log.warn {
"Original and formatted content differ, writing to ${updatedFile.absolutePathString()}..."
}
}
}
if (unfixedErrors > 0) {
exitProcess(1)

Check warning on line 52 in diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt

View check run for this annotation

Codecov / codecov/patch

diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt#L52

Added line #L52 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DiktatCliTest {

val diktatCliProcess = processBuilder.start()
val exitCode = diktatCliProcess.waitFor()
softly.assertThat(exitCode).describedAs("The exit code of Diktat CLI").isZero
softly.assertThat(exitCode).describedAs("The exit code of Diktat CLI").isOne

softly.assertThat(diktatCliLog).isRegularFile

Expand Down
Loading