From bb11a86273c3a3e0c06550e491f7d08262aa2caf Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Sat, 3 Sep 2022 17:43:35 +0200 Subject: [PATCH] Display warning instead of error when no files are matched, and return with exit code 0 Closes #1624 --- CHANGELOG.md | 1 + .../com/pinterest/ktlint/internal/KtlintCommandLine.kt | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14764dea80..5af1082ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Do not show deprecation warning about property "disabled_rules" when using CLi-p ### Added ### Changed +* Display warning instead of error when no files are matched, and return with exit code 0. ([#1624](https://github.com/pinterest/ktlint/issues/1624)) ### Removed diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt index 097b2b74cf..3d426a98dc 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt @@ -274,11 +274,12 @@ internal class KtlintCommandLine { ) } reporter.afterAll() + logger.debug { "${System.currentTimeMillis() - start}ms / $fileNumber file(s) / $errorNumber error(s)" } if (fileNumber.get() == 0) { - logger.error { "No files matched $patterns" } - exitProcess(1) + // Do not return an error as this would implicate that in a multi-module project, each module has to contain + // at least one kotlin file. + logger.warn { "No files matched $patterns" } } - logger.debug { "${System.currentTimeMillis() - start}ms / $fileNumber file(s) / $errorNumber error(s)" } if (tripped.get()) { exitProcess(1) }