JLLeitschuh / ktlint-gradle

A ktlint gradle plugin
MIT License
1.46k stars 160 forks source link

Filter to exclude a generated dir is not working in version 12.1.0 #751

Open edpichler opened 7 months ago

edpichler commented 7 months ago

The filter is not working in version 12.1.0 under Windows using the following configuration:

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
    filter {
        exclude("**/generated/**")
    }
}

Below is how to workaround the problem:

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
   filter {
        exclude { element -> 
            val path = element.file.path
            path.contains("\\generated\\") || path.contains("/generated/") 
        }
    }
}

I haven't tested it but it seems the problem is related to the / when different platforms.

jbruchanov commented 6 months ago

it doesn't seem to be reliably working... I'm using the latest kotlin multiplatform which is generating own Resources... no matter of exclude result, the ktlint fails as it's not following predefined rules

xenomachina commented 5 months ago

it doesn't seem to be reliably working

Perhaps this is why.

brahyam commented 4 months ago

I was having the same problem on 12.1.0 with any combination, moved to 12.1.1 using the config below and was solved:

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
    enableExperimentalRules.set(true)
    filter {
        exclude { element ->
            val path = element.file.path
            path.contains("\\generated\\") || path.contains("/generated/")
        }
    }
}