-
Notifications
You must be signed in to change notification settings - Fork 461
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
Adds ktlint linting for Gradle Kotlin DSL files #129
Adds ktlint linting for Gradle Kotlin DSL files #129
Conversation
I was unable to try creating a |
Great start! I've got a couple concerns: findCompanionScripts and
|
Fair enough.
That use case would be handled by default. I understand your concerns. I can clean it up and remove the "magic" modes. Should the expectation be that the user will just apply the configuration to the root project and be done with it? Also, are you fine with the name? |
The expectation should be that the plugin will act only on the project it is applied to. Here's an example usage: allprojects {
spotless {
kotlinGradle {
ktlint()
}
kotlin {
ktlint()
licenseHeaderFile 'someHeaderFile'
}
}
} Or maybe allprojects {
spotless {
kotlinGradle {
ktlint()
}
}
}
subprojects {
spotless {
kotlin {
ktlint()
licenseHeaderFile 'someHeaderFile'
}
}
} Re: name, I see this as a specialization of the |
So how would this work if I have extra scripts in some How would you tell the difference between a |
TODO list:
|
Here's one way, where only the root project formats the shared scripts spotless {
kotlinGradle {
target '*.gradle.kts', 'extraScripts/*.gradle.kts'
}
}
subprojects {
spotless {
kotlinGradle {
// default target of *.gradle.kts works
}
}
} Here's another way, where every project formats the shared files allprojects {
spotless {
kotlinGradle {
target files('*.gradle.kts'), rootProject.files('extraScripts/*.gradle.kts')
ktlint()
}
}
} I'm all about convention-over-configuration, but the "gradle shared scripts" folder isn't fully standardized, so I don't see a good way to handle this without manually specifying the target. Both approaches above are fairly easy to read and self-documenting. I see that as an advantage over a special-purpose |
So just to make sure I'm 100% sure what you are saying: |
Yep. That's the way all our language-specific formats work. In the |
public KotlinBuildExtension(SpotlessExtension rootExtension) { | ||
super(rootExtension); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no good way to determine the top of a .gradle.kts
file so I removed the licenseHeader
helpers as I realized that the delimiter
wasn't right.
@@ -97,7 +97,7 @@ local.properties | |||
## Plugin-specific files: | |||
|
|||
# IntelliJ | |||
/out/ | |||
out/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had files showing up that should be ignored because of intellij. I can move this to a different PR if you really want but I figured it wasn't worth the overhead. (It's in its own commit).
Great! Only changes left are:
|
I can't check those boxes 😢 but I did make the changes you requested. |
plugin-gradle/README.md
Outdated
ktlint() | ||
|
||
// doesn't support licenseHeader, because scripts don't have a package statement | ||
// to clearly mark where the license should go | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JLLeitschuh does this look okay to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It does still support licenseHeader header, delimiter
because the task extends from FormatExtension
but I leave it as an exercise to the user to create a wacky regex to find the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :)
Awesome! Thanks! |
@nedtwigg Sorry to raise the issue again, but isn't the licenseHeader statement contradicting what we discussed before. |
Always happy to discuss anything further :)
It is OK, and still OK. The primary audience for the README is
It doesn't need to be as complete as the full javadoc. I think sending new users down the regex rabbithole discourages them from the easy wins that Spotless has to offer, by forcing them to face down the full complexity of what is possible right from the start. If I wanted to format the gradle scripts for my main project, I would need to handle files that start with |
Ok, fair enough. Thx for the explanation. Found it funny that you explicitly ruled it out in the ReadMe. Will provide something similar for Groovy. |
I agree it's weird, from an expert perspective, to explicitly rule it out. The |
Closes #115