Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow ktlint invocations without matching sources #1624

Closed
liutikas opened this issue Aug 31, 2022 · 3 comments · Fixed by #1631
Closed

Allow ktlint invocations without matching sources #1624

liutikas opened this issue Aug 31, 2022 · 3 comments · Fixed by #1631
Labels
bug cli ktlint command line interface
Milestone

Comments

@liutikas
Copy link
Contributor

Expected Behavior

We use Gradle to invoke ktlint via a custom task. We pass in src/**/*.kt !src/**/test-data/**/*.kt !src/**/external/**/*.kt for what files we want to analyze. We create these tasks regardless if there is a matching kt file in the project, so that we don't have to do I/O during Gradle configuration. We have some project that have no matching files. 0.46 and older versions of ktlint, these invocations would just work.

example full command

/ssd/ssd5/androidx-main/prebuilts/jdk/jdk11/linux-x86/bin/java -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/0.47.0/ktlint-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-baseline/0.47.0/ktlint-reporter-baseline-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-checkstyle/0.47.0/ktlint-reporter-checkstyle-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-json/0.47.0/ktlint-reporter-json-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-format/0.47.0/ktlint-reporter-format-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-html/0.47.0/ktlint-reporter-html-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-plain/0.47.0/ktlint-reporter-plain-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-reporter-sarif/0.47.0/ktlint-reporter-sarif-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-ruleset-experimental/0.47.0/ktlint-ruleset-experimental-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-ruleset-standard/0.47.0/ktlint-ruleset-standard-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-ruleset-test/0.47.0/ktlint-ruleset-test-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/pinterest/ktlint/ktlint-core/0.47.0/ktlint-core-0.47.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.7.10/kotlin-compiler-embeddable-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/com/github/shyiko/klob/klob/0.2.1/klob-0.2.1.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/info/picocli/picocli/4.6.3/picocli-4.6.3.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/io/github/microutils/kotlin-logging-jvm/2.1.21/kotlin-logging-jvm-2.1.21.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.7.10/kotlin-stdlib-jdk8-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/ec4j/core/ec4j-core/0.3.0/ec4j-core-0.3.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/io/github/detekt/sarif4k/sarif4k/0.0.1/sarif4k-0.0.1.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-reflect/1.7.10/kotlin-reflect-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.10/kotlin-stdlib-jdk7-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlinx/kotlinx-serialization-json-jvm/1.1.0/kotlinx-serialization-json-jvm-1.1.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlinx/kotlinx-serialization-core-jvm/1.1.0/kotlinx-serialization-core-jvm-1.1.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-stdlib/1.7.10/kotlin-stdlib-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-script-runtime/1.7.10/kotlin-script-runtime-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-daemon-embeddable/1.7.10/kotlin-daemon-embeddable-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/intellij/deps/trove4j/1.0.20200330/trove4j-1.0.20200330.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/net/java/dev/jna/jna/5.6.0/jna-5.6.0.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/ch/qos/logback/logback-core/1.2.11/logback-core-1.2.11.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/kotlin/kotlin-stdlib-common/1.7.10/kotlin-stdlib-common-1.7.10.jar:/ssd/ssd5/androidx-main/prebuilts/androidx/external/org/jetbrains/annotations/13.0/annotations-13.0.jar com.pinterest.ktlint.Main --android --reporter=plain --reporter=checkstyle,output=../../../../out/androidx/appsearch/appsearch-platform-storage/build/reports/ktlint/ktlint-checkstyle-report.xml src/**/*.kt !src/**/test-data/**/*.kt !src/**/external/**/*.kt

Observed Behavior

Starting with ktlint 0.47, it just exits with

14:41:03.584 [main] ERROR com.pinterest.ktlint.internal.KtlintCommandLine - No files matched [src/**/*.kt, !src/**/test-data/**/*.kt, !src/**/external/**/*.kt]

Steps to Reproduce

Call ktlint with arguments that have no matching files.

Your Environment

  • Version of ktlint used: 0.47
  • Operating System and version: Linux

If we do not want this behavior by default, ideally there is a flag to tell ktlint to skip running if there are no matching files.

@paul-dingemans
Copy link
Collaborator

This is a regression bug. The warning will stay after the fix but it should just exit with status code zero.

@paul-dingemans paul-dingemans added cli ktlint command line interface bug labels Sep 1, 2022
@paul-dingemans paul-dingemans added this to the 0.47.1 milestone Sep 1, 2022
@liutikas
Copy link
Contributor Author

liutikas commented Sep 1, 2022

Could we please add a flag to not warn about it? We'd really like to avoid polluting stdout.

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Sep 2, 2022

Could we please add a flag to not warn about it? We'd really like to avoid polluting stdout.

I do not want to introduce a flag to surpress this specific warning. Ktlint already has to many obscure flags and options which do hinder development.

I will think about a possibility to suppress all warnings. Currently it is already possibly to influence the log level by setting flag --debug or --trace. Maybe I should replace those option with a new option --log-level=<level>. Setting that flag to --log-level=error would result in only displaying log messages at error (or higher) level and thus suppressing all warning, info, debug and trace messages. But this will not be released in the bugfix release 0.47.1.

paul-dingemans referenced this issue Sep 3, 2022
Print an error message and return with non-zero exit code when no files are found that match with the globs

Closes #629
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Sep 3, 2022
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Sep 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug cli ktlint command line interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants