-
Notifications
You must be signed in to change notification settings - Fork 1
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
configure ktlint with custom rules #9
Changes from all commits
1e7ce0a
5d6dc91
472e3e1
e3c3d41
538af0b
a70c2e6
1a29b19
8b27907
8bf3418
aa04489
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.gradle.dsl | ||
|
||
import aws.sdk.kotlin.gradle.util.verifyRootProject | ||
import org.gradle.api.Project | ||
import org.gradle.api.attributes.Bundling | ||
import org.gradle.api.tasks.JavaExec | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.named | ||
import org.gradle.kotlin.dsl.register | ||
|
||
/** | ||
* Configure lint rules for the project | ||
* @param lintPaths list of paths relative to the project root to lint (or not lint). | ||
*/ | ||
fun Project.configureLinting(lintPaths: List<String>) { | ||
verifyRootProject { "Kotlin SDK lint configuration is expected to be configured on the root project" } | ||
|
||
val ktlint = configurations.create("ktlint") { | ||
attributes { | ||
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) | ||
} | ||
} | ||
|
||
// TODO - is there anyway to align this with the version from libs.versions.toml in this project/repo | ||
val ktlintVersion = "0.48.1" | ||
dependencies { | ||
ktlint("com.pinterest:ktlint:$ktlintVersion") | ||
} | ||
|
||
// add the buildscript classpath which should pickup our custom ktlint-rules (via runtimeOnly dep on this plugin) | ||
// plus any custom rules added by consumer | ||
val execKtlintClaspath = ktlint + buildscript.configurations.getByName("classpath") | ||
tasks.register<JavaExec>("ktlint") { | ||
description = "Check Kotlin code style." | ||
group = "Verification" | ||
classpath = execKtlintClaspath | ||
mainClass.set("com.pinterest.ktlint.Main") | ||
args = lintPaths | ||
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") | ||
} | ||
|
||
tasks.register<JavaExec>("ktlintFormat") { | ||
description = "Auto fix Kotlin code style violations" | ||
group = "formatting" | ||
classpath = execKtlintClaspath | ||
mainClass.set("com.pinterest.ktlint.Main") | ||
args = listOf("-F") + lintPaths | ||
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.gradle.kmp | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.the | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
/** | ||
* Allows configuration from parent projects subprojects/allprojects block when they haven't configured the KMP | ||
* plugin but the subproject has applied it. The extension is otherwise not visible. | ||
*/ | ||
fun Project.kotlin(block: KotlinMultiplatformExtension.() -> Unit) { | ||
configure(block) | ||
} | ||
val Project.kotlin: KotlinMultiplatformExtension get() = the() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
allprojects { | ||
group = "aws.sdk.kotlin" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it correct to have this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't publishing this so it doesn't really matter. We have to choose some group though and the only groups we own are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok, this one should be fine |
||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
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.
Question: Would it work to just use `val ktlintVersion: String by project" and pull it in from the root project? That would mean potentially separate versions across the repos but that's what we have now and we're not (yet) planning to commonize the version numbers right?
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.
We are planning to commonize the version numbers (for ktlint anyway) because we've moved the rules into this plugin/project. Downstream consumers won't need to set ktlint version at all, just the paths to lint. Theres no real reason to make the downstream consumers set a version, it doesn't gain us anything really.