Skip to content

Commit

Permalink
Return exit code 1 in case violations have been found but file is unc…
Browse files Browse the repository at this point in the history
…hanged (#2803)

In very rare cases it is possible that Lint violations are detected while formatting but that they have opposite effects and the file gets not altered at all. As the logging already might contain the message "Format was not able to resolve all violations which (theoretically) can be autocorrected in file ..." the format may not return with exit code 0.

Closes #2795
  • Loading branch information
paul-dingemans authored Sep 18, 2024
1 parent 97a9b44 commit 6d0d402
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ internal class KtlintCommandLine :
}
} ?: NO_AUTOCORRECT
}.also { formattedFileContent ->
if (ktlintCliErrors.isNotEmpty() && code.content == formattedFileContent) {
// In very rare cases it is possible that Lint violations are detected but that they have opposite effects and the
// file gets not altered at all. This is to be treated as unfixable error.
containsUnfixedLintErrors.set(true)
}
if (forceLintAfterFormat && code.content != formattedFileContent) {
// Rerun lint to check that the formatted code can still be successfully parsed.
try {
Expand Down Expand Up @@ -721,7 +726,7 @@ internal class KtlintCommandLine :
q.put(executorService.submit(task))
}
q.put(pill)
} catch (e: InterruptedException) {
} catch (_: InterruptedException) {
// we've been asked to stop consuming sequence
} finally {
executorService.shutdown()
Expand Down

0 comments on commit 6d0d402

Please sign in to comment.