Skip to content

Commit

Permalink
Return exit code 1 when not all errors are fixed (#1868)
Browse files Browse the repository at this point in the history
- calculate only not fixed errors
- return 1 when there are errors
  • Loading branch information
nulls authored Dec 18, 2023
1 parent 3ba0fb0 commit b3cd098
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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.Path
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 @@ fun main(args: Array<String>) {
)

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)
}
}
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

0 comments on commit b3cd098

Please sign in to comment.