-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to exclude files from being formatted? #724
Comments
Hey. It seems more like a bug to me. Have you found any workaround? |
I haven't - for now, we're reverting the changes we don't want after the |
I've found one. I updated the |
How did you exclude them? I tried both a
Or the following section matching generated files in the top-level
Neither prevented |
EDIT: I realized that 12.1.0 was released after this issue, so I guess I have a separate issue. For me, the exclude filter stopped working in 12.1.0 but works if I revert to 12.0.3. |
Interesting, I am not aware of any changes made to how filters are applied. This warrants further investigation |
I'm also experiencing problems with filters. Both versions 12.1.0 and 12.0.3. Both ktlintFormat and ktlintCheck tasks ignore my filter ktlint {
filter {
exclude("**/generated/**")
}
} Still processes |
Ultimately, we just use Gradle's built in https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html The behavior of this filter is, admittedly, confusing, but usually it's not our bug when people have issues. It's usually that the filter being specified isn't correct. I chose to use Gradle's built in filtering with a direct pass-through to the source set to minimize the amount of custom filtering we needed to expose, which many other plugins do, and fail to do correctly. Unfortunately, I often don't have the answers regarding why it isn't working as expected. Ultimately, these are Gradle APIs talking to other Gradle API'S, without ktlint-gradle in the middle. If you believe there is a bug in our implementation of how we are using PaternFilterable, please provide a minimal reproducer, and we will see what we can do to fix it. One debugging pattern I'd suggest is printing every file passed to the |
For anyone else who finds this thread looking for a solution, the Ktlint FAQ has a recommendation: https://pinterest.github.io/ktlint/dev-snapshot/faq/#how-do-i-disable-ktlint-for-generated-code In short, add the following to your [some/path/to/generated/code/**/*]
ktlint = disabled This may not work for everyone's situation, and I think it is unfortunate that I can't just use the Gradle |
Using this configuration:
We have some files in those
/gen/
folders that are generated, but also checked in Git. We don't want to format them. Running:ktlintCheck
properly ignores them, but:ktlintFormat
seems to ignore filters - those generated files get formatted.Is there an option to apply filters to
:ktlintFormat
?The text was updated successfully, but these errors were encountered: