Skip to content

Commit

Permalink
Warn on no files matched (#1631)
Browse files Browse the repository at this point in the history
* Display warning instead of error when no files are matched, and return with exit code 0
  • Loading branch information
paul-dingemans committed Sep 3, 2022
1 parent 3c71f71 commit e8ac8f6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ktlint/src/test/kotlin/com/pinterest/ktlint/BaseCLITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ abstract class BaseCLITest {

companion object {
private const val WAIT_INTERVAL_DURATION = 100L
private const val WAIT_INTERVAL_MAX_OCCURRENCES = 100
private const val WAIT_INTERVAL_MAX_OCCURRENCES = 1000
val testProjectsPath: Path = Paths.get("src", "test", "resources", "cli")
const val BASE_DIR_PLACEHOLDER = "__TEMP_DIR__"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class EditorConfigDefaultsLoaderCLITest : BaseCLITest() {
val projectDirectory = "$BASE_DIR_PLACEHOLDER/editorconfig-path/project"
runKtLintCliProcess(
"editorconfig-path",
listOf("--editorconfig=$projectDirectory/editorconfig-boolean-setting", "--debug"),
listOf("--editorconfig=$projectDirectory/editorconfig-boolean-setting"),
) {
assertErrorExitCode()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SimpleCLITest : BaseCLITest() {
"too-many-empty-lines",
listOf("SomeOtherFile.kt"),
) {
assertErrorExitCode()
assertNormalExitCode()

assert(normalOutput.find { it.contains("No files matched [SomeOtherFile.kt]") } != null) {
"Unexpected output:\n${normalOutput.joinToString(separator = "\n")}"
Expand Down

0 comments on commit e8ac8f6

Please sign in to comment.