ktlint: Traversing the directory hierarchy is broken on Windows as of version 0.47

Expected Behavior

Running ktlint w/o specifying any input files previously made it search for *.kt and *.kts files, starting from the current directory, e. g.:

$ ./ktlint
14:54:01.402 [main] INFO com.pinterest.ktlint.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
10:56:53.905 [main] DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - 6821ms / 14 file(s) / 167 error(s)

This behaviour still holds when ktlint is run from the command line on Linux or Mac OS X.

Observed Behavior

Yet, using just the very same command line switches on Windows (i. e. when running ktlint from Git Bash) results in no input files being found:

15:01:09.889 [main] INFO com.pinterest.ktlint.internal.KtlintCommandLine - Enable default patterns [**\\*.kt, **\\*.kts]
15:01:10.457 [main] ERROR com.pinterest.ktlint.internal.KtlintCommandLine - No files matched [**\\*.kt, **\\*.kts]

This is a clear regression against version 0.46.1 and, apparently, has been caused by the recent changes which re-enable (sort of — see #1601) the parsing of Ant-like path patterns (e.g.: **/*.kt) — which was broken in version 0.46.1.

Steps to Reproduce

  1. Download the fat JAR from https://github.com/pinterest/ktlint/releases/tag/0.47.0.
  2. Run the far JAR against any non-empty codebase on Windows:
    java -Xmx512m --add-opens java.base/java.lang=ALL-UNNAMED -jar ktlint
    

Your Environment

  • Version of ktlint used: 0.47
  • Relevant parts of the .editorconfig settings: none
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): CLI
  • Version of Gradle used (if applicable): N/A
  • Operating System and version:
    • MINGW64_NT-10.0-19043 unit-725 3.3.4-341.x86_64 2022-05-09 11:56 UTC x86_64 Msys
    • Linux unit-725 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 GNU/Linux

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 29 (4 by maintainers)

Commits related to this issue

Most upvoted comments

in this exact project, all the gradle files are implemented in groovy. So the assumption about build.gradle.kts is wrong.

Tnx for clarifying this false assumption. I can now reproduce the problem and will create a new issue for fixing it.

@paul-dingemans I think the problem mentioned by @CokieForever still remains. The only difference in my case is - I am using Mac OS X machine.

I have a build.gradle file in a module defined in a subdirectory of the $rootDir of my project. I am interested in running the static analysis against all the modules and due to the error explained by @CokieForever - it is impossible.

I’ve tested ktlint 0.47.1 which @CokieForever mentioned as working in his case. With no luck. I’ve also tested the most recent one - 0.49.0 with exact same result. I’ve changed either gradle dependency and a ktlint CLI binary installed on my machine.

The FileUtils class point to a current directory as a starting point of file tree walk and finds no files to scan.

Here is the output of a debug logger:

DEBUG com.pinterest.ktlint.internal.FileUtils - Start walkFileTree for rootDir: '/Users/tommus/Code/android/my-project-android/infrastructure/static-analysis'
   include:
[      - sun.nio.fs.UnixFileSystem$3@11a9e7c8]
   exclude:
[]
DEBUG com.pinterest.ktlint.internal.FileUtils - Discovered 0 files to be processed in 6 ms
DEBUG com.pinterest.ktlint.internal.KtlintCommandLine - 66ms / 0 file(s) / 0 error(s)

With respective warnings (based on the arguments provided):

WARN com.pinterest.ktlint.internal.KtlintCommandLine - No files matched [**/*.kt]
WARN com.pinterest.ktlint.internal.KtlintCommandLine - No files matched [../../**/*.kt]
WARN com.pinterest.ktlint.internal.KtlintCommandLine - No files matched [/Users/tommus/Code/android/my-project-android/**/*.kt]

I have tested multiple variants of the arguments:

  • **/*.kt
  • ../../**/*.kt
  • $rootDir/**/*.kt (as it is a custom gradle task)

In each case - the starting point of the file walk was defined incorrectly and scanned only the files from the current directory (pwd in case of ktlint CLI and a build.gradle parent directory in case of Gradle task).

Side note: The last working version in the setup described above - was 0.39.0. I’ve checked all the versions from 0.49.0 down to 0.40.0 and it seems the changes to globs introduced the problem.

Nevermind, nevermind, apparently https://github.com/pinterest/ktlint/issues/1288 was fixed in 0.47.1 as well, or at least it works for me again 😄

@paul-dingemans, I’ll test and get back to you tomorrow morning.

Yes, that is already in place. But you don’t have an actual filesystem in CI. So we use jimfs to simulate that. The windows version of it, lacks some functionality. So certain unit tests can not run on CI.