`filter` config seems to be ignored
See original GitHub issueA bit of context
Due to some problems with Android SafeArgs
Gradle plugin I had to add additional source sets into feature modules (Gradle sub-projects)
sourceSets {
getByName("test").java.srcDir("${project.rootDir}/app/build/generated/source/navigation-args/debug")
}
Ktlint Issue
Now I am experiencing an issue where filter
configuration seems to be ignored and checks ...Args
classes that are located inside the generated
folder (I am not sure if this is related to the above change, but 100% reproducible).
I have added to root build.gradle.kts
file:
filter {
exclude("**/generated/**")
}
However ktlint gradle still seens to check classes in generated
folder
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:26:30
Since this class is generated by SafeArgs
Gradle plugin I have no control on code format and naturally, I want it not to be checked by ktlint.
Also, note that after adding the same source set to different modules this file is checked 3 times.
Reproduce Here is the branch to test it https://github.com/igorwojda/android-showcase/tree/ktlint-filter-not-working
- Open this project in Android Studio
- Build project, so
AlbumDetailFragmentArgs
is generated (Build
->Make project
) - Run ktlint
./gradlew ktlintcheck
Result
> Task :feature_favourite:ktlintTestSourceSetCheck FAILED
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:26:30: Unexpected spacing before ":" (colon-spacing)eSetCheck
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:35:29: Unexpected spacing before ":" (colon-spacing)
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:44:24: Unexpected spacing before ":" (colon-spacing)
"checkstyle" report written to /Users/igorwojda/StudioProjects/android-showcase/feature_favourite/build/reports/ktlint/ktlintTestSourceSetCheck.xml
> Task :feature_profile:ktlintTestSourceSetCheck FAILED
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:26:30: Unexpected spacing before ":" (colon-spacing)
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:35:29: Unexpected spacing before ":" (colon-spacing)
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:44:24: Unexpected spacing before ":" (colon-spacing)
"checkstyle" report written to /Users/igorwojda/StudioProjects/android-showcase/feature_profile/build/reports/ktlint/ktlintTestSourceSetCheck.xml
> Task :feature_album:ktlintTestSourceSetCheck FAILED
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:26:30: Unexpected spacing before ":" (colon-spacing)eSetCheck
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:35:29: Unexpected spacing before ":" (colon-spacing)
/Users/igorwojda/StudioProjects/android-showcase/app/build/generated/source/navigation-args/debug/com/igorwojda/showcase/feature/album/presentation/albumdetails/AlbumDetailFragmentArgs.kt:44:24: Unexpected spacing before ":" (colon-spacing)
"checkstyle" report written to /Users/igorwojda/StudioProjects/android-showcase/feature_album/build/reports/ktlint/ktlintTestSourceSetCheck.xml
Expected result
All checks related to AlbumDetailFragmentArgs.kt
would be ignored (due to filter rule). Also is this class would not be ignored I would expect no duplicated checks.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (2 by maintainers)
Top GitHub Comments
But adding
as mentioned here: https://github.com/JLLeitschuh/ktlint-gradle/issues/222#issuecomment-480758375 does work for me. Not quite sure why the one works and the other one not to be honest.
@igorwojda your issue is that added files are located outside module project root dir:
Proper solution would be replace regex with:
More details you could find in this issue: https://github.com/gradle/gradle/issues/3417
@Globegitter @plannigan I don’t know details of you issues, but could you check if solution above is working for your cases as well.
I would add this solution to project README.