question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`filter` config seems to be ignored

See original GitHub issue

A 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

  1. Open this project in Android Studio
  2. Build project, so AlbumDetailFragmentArgs is generated (Build -> Make project)
  3. 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Globegittercommented, Aug 12, 2019

But adding

ktlint {
    enableExperimentalRules.set(true)
    filter {
        // exclude("**/generated/**")
        exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/generated/") }
    }
}

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.

1reaction
Tapchicomacommented, Sep 9, 2019

@igorwojda your issue is that added files are located outside module project root dir:

This is because regex-based matching is done on the relative path, i.e. the path following the root directory of each tree.

Proper solution would be replace regex with:

exclude { element -> element.file.path.contains("generated/") }

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log4j2 Regexfilter seems to ignore filter configuration
Solution: the regex seems to have been wrong, removing the spaces around 'startup' makes it work. <RegexFilter regex=".*startup.
Read more >
Drush cim doesn't respect config ignore filters - Drupal
Basically it seems that Config Filter module is not involved during drush cim. Also I do not use Config Split module.
Read more >
[Solved] Ignored data filter not working - Unimus forum
I want to include the line in the config, but exclude it from detecting a change. I have hard coded the AUX port...
Read more >
Filter with * servlet-name binding is ignored on EAP 7
We use a filter config like the following on EAP 6 and earlier but it seems to be ignored on EAP 7: Raw....
Read more >
How to set ignore filter in Event Rules to ignore - ServiceNow
Select this option to inhibit an alert from being created and be associated with the event. To configure conditions to which the event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found