How do you tell ktlint in android to exclude specific paths in the project?
Asked Answered
O

2

12

Currently when I want to format my code, I run this in the terminal in my android studio directory

https://github.com/pinterest/ktlint

./gradlew ktlintFormat

This command works great, but recently I added some folders into my project and the code in there is being checked by the ktlintFormat command. I wish to exclude those folders from being checked. Does anyone know if this is possible?

Oddment answered 29/11, 2020 at 4:52 Comment(0)
P
12
ktlint {
    filter {
        exclude("**/generated/**")
        include("**/kotlin/**")
    }
}
Phiz answered 2/5, 2021 at 10:46 Comment(3)
Doesn't work with JLLeitschuh/ktlint-gradle. See more here: github.com/JLLeitschuh/ktlint-gradle/issues/266.Oberammergau
filter is not working with latest versionKidskin
@TiarêBalbi here's a temporary workaround: https://mcmap.net/q/937908/-how-do-you-tell-ktlint-in-android-to-exclude-specific-paths-in-the-projectClaudelle
C
0

In general, العبد's answer is correct. However, as of 12.1.1 of the ktlint Gradle plugin this doesn't work.

A working alternative until this is fixed:

filter {
    exclude { element ->
        def path = element.file.path
        path.contains("/generated/") || path.contains("/kotlin/")
    }
}
Claudelle answered 12/8 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.