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

Warn on no files matched #1631

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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