If file paths are passed in the command line, and path of one file is a subpath of another file, then ktlint only reports issues of the file with the shortest path.
For example if there're 2 files with issues:
/src/main/java/org/example/bugtest/SampleBadClass.kt/src/main/java/org/example/bug/AnotherBadClass.ktthen only the issues of the AnotherBadClass.kt are reported.
This only happens if one's file path is a substring of another's file path. In the example above: /src/main/java/org/example/bug is a substring of src/main/java/org/example/bugtest. The case would also reproduce on the following paths of the second file:
/src/main/java/org/example/bugtes/AnotherBadClass.kt/src/main/java/org/example/bugte/AnotherBadClass.kt/src/main/java/org/example/b/AnotherBadClass.ktIf the file with the shortest path doesn't have issues or that file doesn't exist then no issues are reported at all:
/src/main/java/org/example/bugtest/SampleBadClass.kt/src/main/java/org/example/bug/NonExistingFile.ktIssues from all files are correctly reported
/src/main/java/org/example/bugtest/SampleBadClass.kt:
package org.example.bugtest
// Unnecessary block ("{}")
// Unexpected blank line(s) before "}"
// Needless blank line(s)
object SampleBadClass {
}
/src/main/java/org/example/bug/AnotherBadClass.kt:
package org.example.bug
// unnecessary block {}
object AnotherBadClass {}
/src/main/java/org/example/bug/AnotherGoodClass.kt:
package org.example.bug
// no issues
object AnotherGoodClass {}
ktlint "src/main/java/org/example/bugtest/SampleBadClass.kt" finds issues as expected:
/Users/…/src/main/java/org/example/bugtest/SampleClass.kt:3:20: Unnecessary block ("{}")
/Users/…/src/main/java/org/example/bugtest/SampleClass.kt:4:1: Unexpected blank line(s) before "}"
/Users/…/src/main/java/org/example/bugtest/SampleClass.kt:5:1: Needless blank line(s)
ktlint "src/main/java/org/example/bugtest/SampleBadClass.kt" "src/main/java/org/example/bug/AnotherGoodClass.kt" reports no issues (issues in SampleBadClass found before are now not reported):
ktlint "src/main/java/org/example/bugtest/SampleBadClass.kt" "src/main/java/org/example/bug/AnotherBadClass.kt" reports only issues from AnotherBadClass.kt (issues in SampleBadClass found before are again not reported):
/Users/…/src/main/java/org/example/bug/AnotherBadClass.kt:4:24: Unnecessary block ("{}")
The bug also reproduces if multiple wildcards are used:
ktlint "src/main/java/org/example/bug/*.kt" "src/main/java/org/example/bugtest/*.kt" only reports issues from AnotherBadClass.kt skipping SampleBadClass.kt:
/Users/…/src/main/java/org/example/bug/AnotherBadClass.kt:4:24: Unnecessary block ("{}")
ktlint gradle plugin runs ktlint exaclty like in the examples above, specifying a path to every single file. That currently leads to inconsistent reports between ktlint command line run (without file paths) and gradlew ktlintCheck.
Seeing the same issue.
Also seeing the same issue. I'm guessing there's a problem here
Was able to reproduce, will fix for the next release.
Hi @Tapchicoma,
The current workaround kills any ability to use negated globs (begin with "!") because it is only additive with the results. I have forked the klob library and fixed the issue and published a package to bintray for now, as well as submitted pull requests to the original project. The new package was just approved for inclusion into jcenter under the artifact io.codetactics.klob:klob:0.2.1.
I will also submit a pull request to revert the workaround commit, with a small addition to also skip hidden files similar to the default paths. By my testing, this will allow inclusive & exclusive globs, while also correcting this issue at the root of the problem.