-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configure ktlint with custom rules (#9)
- Loading branch information
Showing
7 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
build-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/CodeStyle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
build-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/KmpProjectExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters