-
Notifications
You must be signed in to change notification settings - Fork 49
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
Kotlinter is not ignoring generated files #208
Comments
Since I wasnt sure the exact format expected, the other exclude variations I tried are:
|
Thanks Josh, let me see if I can figure this one out. Is that the same "build" directory as the one gradle uses for output? The |
there is a
kotlinter is only defined in the root project.
Yes! Thanks so much for the quick follow-up. I'm very new to gradle so I may have done something wrong as well |
Based on this issue in ktlint and the ant pattern docs it looks like the correct syntax is @jeremymailen I tried both formats just now and it still didnt work 🙃 |
Can you show what the project structure looks like? Are these generated files being created by another gradle plugin or custom build code? I ask because |
is there a way to log the relative root for a source set? |
You should be able to do something like this in your Gradle script sourceSets.forEach {
val dirPaths = it.java.srcDirs.map { d -> d.path }
println("${it.name} : ${dirPaths.joinToString()}")
} Kotlin JVM gradle plugin uses Typically a standard project will have two sourceSets main and test. For kotlinter itself
|
Do you have any thoughts on the above questions -- what's generating your sources and your project structure? |
@jeremymailen where do I add that |
Sorry, was out of town -- if you're still looking for a solution: gradle -d lintKotlin | grep linting You'll see output including the relative file path and name of the lint task that is operating on it. For example:
The key is to make sure you're modifying the excludes for the correct lint task and a matching path. That's helpful info about the Apollo plugin. It looks like what it does is add a new path to each sourceSet under |
Ok, did a few experiments with ordinary source sets. It appears the exclude path is oriented to the package, regardless of the root. For example to exclude my above file you'd need to: tasks {
"lintKotlinTest"(LintTask::class) {
exclude("/org/jmailen/gradle/kotlinter/functional/KotlinProjectTest.kt")
}
} Or any glob including that exact path. I know it's not the most user friendly when there's a whole root you need to exclude. Is there a pattern within the package or file names you can target instead? I suppose we could break our dependency on Gradle's |
I did try all of the variants that are described in the OP and with the generated blob as well:
Those did not work. I am currently just contemplating running a ktlint check without the plugin, but it would be nice if the plugin was able to do this on its own. |
Ok, see my other note above -- it will work, but you must use a path matcher on the package or filename portion. |
So with that I can just do the following?
|
No you must use the package and filename portion of the path. I'm just imagining how apollo might choose a package, but hopefully it's unique. tasks {
"lintKotlinMain"(LintTask::class) {
exclude("service/graphql/*.kt")
}
} |
Ah ok, but apollo unfortunately does not create a package for anything but primitive types. So most of the generated classes are not in a package. In my case for instance, I simply do |
It's looks like they provide a Also seems like here:
|
Yes, it is possible to create one if required, but that's not the default configuration. Do I need to set a package name and then create the path? |
I'm not an apollo user. I'm just noting in their docs you can change the package. I don't know their rationale for choosing the root package as default. Although Kotlinter wasn't designed specifically to support or not support apollo, I'm guessing any tool which generates source code will allow you to choose the output package because you'd need to be able to do that to prevent conflicts or control package visibility. |
So from what I understand, the As an example, lint errors are here: This does not work/exclude the file(s):
But this does:
Can I somehow still match on the 'generated'-part? |
You are correct @RdeWilde, the way It would be nice, but I wonder if we'll need it? It seems like any code generation plugin will allow you to specify a unique output package. Wouldn't you want a unique package anyway to keep your generated source separate in namespace from your hand written code? |
That could be true. But basically I'd like to just exclude anything from the If it is too much hassle, this can also work. Suggestion not requirement :-) |
Yes, will add it as an enhancement request. The Gradle Quality plugin has a similar extra param |
Closing for now and will take note of the enhancement request. |
Just catching up on this. Thanks @jeremymailen ! I got the exclude working now. +1 to the enhancement discussed above, it would have been a more intuitive solution to discover and is better "documentation" that it is generated code being ignored. |
Cool, noted. Glad you're able to find a solution for the meantime. |
Could you explain how you make it work?
But with this plugin it doesnt work at all We need a standard way to fix this problem...This issue must be open. EDIT: Found a solution
|
Thanks this solves my problem! |
- Updated lint to use `lintKotlinMain` instead of `lintKotlin` - Fix generated file being included in kotlinter. jeremymailen/kotlinter-gradle#208 - Update kotlinter from 4.3.0 to 4.4.0
Even more DRY: import org.jmailen.gradle.kotlinter.tasks.ConfigurableKtLintTask
withType<ConfigurableKtLintTask> {
exclude { it.file.path.contains("generated/") }
} |
I have several generated kotlin files in my app (inside a
build
directory) which creates kotlin code thatktlint
doesnt like. Since I have no control over the code generation and it is not being checked into git I would like ktlint to ignore the files within thebuild
directory.I tried adding several variations of
exclude("build/**")
but each time ktlint was failing on the generated files. Is there any way to ignore thebuild
directory?Note: I added the exclude directory to
"lintKotlinMain"(org.jmailen.gradle.kotlinter.tasks.LintTask::class) {
as stated in the READMEThanks so much!
The text was updated successfully, but these errors were encountered: