Skip to content

Commit 9fec3d6

Browse files
authored
Migrate to ktfmt (#1871)
1 parent 2620e88 commit 9fec3d6

File tree

92 files changed

+4098
-3941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4098
-3941
lines changed

.editorconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ ij_kotlin_line_break_after_multiline_when_entry = false
1616
ij_kotlin_name_count_to_use_star_import = 2147483647
1717
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
1818
ij_kotlin_packages_to_use_import_on_demand = unset
19-
ktlint_code_style = intellij_idea
20-
ktlint_standard_function-expression-body = disabled
21-
ktlint_standard_mixed-condition-operators = disabled
2219

2320
[*.md]
2421
trim_trailing_whitespace = false

build.gradle.kts

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,16 @@ plugins {
1919
}
2020

2121
version = providers.gradleProperty("VERSION_NAME").get()
22+
2223
group = providers.gradleProperty("GROUP").get()
24+
2325
description = providers.gradleProperty("POM_DESCRIPTION").get()
2426

25-
dokka {
26-
dokkaPublications.html {
27-
outputDirectory = rootDir.resolve("docs/api")
28-
}
29-
}
27+
dokka { dokkaPublications.html { outputDirectory = rootDir.resolve("docs/api") } }
3028

3129
kotlin {
3230
explicitApi()
33-
@OptIn(ExperimentalAbiValidation::class)
34-
abiValidation {
35-
enabled = true
36-
}
31+
@OptIn(ExperimentalAbiValidation::class) abiValidation { enabled = true }
3732
compilerOptions {
3833
allWarningsAsErrors = true
3934
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
@@ -56,18 +51,15 @@ lint {
5651
}
5752

5853
spotless {
59-
kotlin {
60-
ktlint(libs.ktlint.get().version)
61-
}
62-
kotlinGradle {
63-
ktlint(libs.ktlint.get().version)
64-
}
54+
kotlin { ktfmt(libs.ktfmt.get().version).googleStyle() }
55+
kotlinGradle { ktfmt(libs.ktfmt.get().version).googleStyle() }
6556
}
6657

67-
val testPluginClasspath by configurations.registering {
68-
isCanBeResolved = true
69-
description = "Plugins used in integration tests could be resolved in classpath."
70-
}
58+
val testPluginClasspath by
59+
configurations.registering {
60+
isCanBeResolved = true
61+
description = "Plugins used in integration tests could be resolved in classpath."
62+
}
7163

7264
val testKit by sourceSets.creating
7365
val testKitImplementation by configurations.getting
@@ -77,18 +69,18 @@ configurations.configureEach {
7769
API_ELEMENTS_CONFIGURATION_NAME,
7870
RUNTIME_ELEMENTS_CONFIGURATION_NAME,
7971
JAVADOC_ELEMENTS_CONFIGURATION_NAME,
80-
SOURCES_ELEMENTS_CONFIGURATION_NAME,
81-
-> outgoing {
82-
// Main/current capability.
83-
capability("com.gradleup.shadow:shadow-gradle-plugin:$version")
84-
85-
// Historical capabilities.
86-
capability("io.github.goooler.shadow:shadow-gradle-plugin:$version")
87-
capability("com.github.johnrengelman:shadow:$version")
88-
capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version")
89-
capability("gradle.plugin.com.github.johnrengelman:shadow:$version")
90-
capability("com.github.jengelman.gradle.plugins:shadow:$version")
91-
}
72+
SOURCES_ELEMENTS_CONFIGURATION_NAME ->
73+
outgoing {
74+
// Main/current capability.
75+
capability("com.gradleup.shadow:shadow-gradle-plugin:$version")
76+
77+
// Historical capabilities.
78+
capability("io.github.goooler.shadow:shadow-gradle-plugin:$version")
79+
capability("com.github.johnrengelman:shadow:$version")
80+
capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version")
81+
capability("gradle.plugin.com.github.johnrengelman:shadow:$version")
82+
capability("com.github.jengelman.gradle.plugins:shadow:$version")
83+
}
9284
}
9385
}
9486

@@ -108,11 +100,12 @@ configurations.named(API_ELEMENTS_CONFIGURATION_NAME) {
108100
)
109101
}
110102

111-
val testGradleVersion: String = providers.gradleProperty("testGradleVersion").orNull.let {
112-
val value = if (it == null || it == "current") GradleVersion.current().version else it
113-
logger.lifecycle("Using Gradle $value in tests")
114-
value
115-
}
103+
val testGradleVersion: String =
104+
providers.gradleProperty("testGradleVersion").orNull.let {
105+
val value = if (it == null || it == "current") GradleVersion.current().version else it
106+
logger.lifecycle("Using Gradle $value in tests")
107+
value
108+
}
116109

117110
dependencies {
118111
compileOnly(libs.develocity)
@@ -141,17 +134,15 @@ dependencies {
141134
}
142135

143136
testing.suites {
144-
getByName<JvmTestSuite>("test") {
145-
dependencies {
146-
implementation(libs.xmlunit)
147-
}
148-
}
137+
getByName<JvmTestSuite>("test") { dependencies { implementation(libs.xmlunit) } }
149138
register<JvmTestSuite>("documentTest") {
150139
targets.configureEach {
151140
testTask {
152-
val docsDir = file("docs").also {
153-
if (!it.exists() || !it.isDirectory) error("Docs dir $it does not exist or is not a directory.")
154-
}
141+
val docsDir =
142+
file("docs").also {
143+
if (!it.exists() || !it.isDirectory)
144+
error("Docs dir $it does not exist or is not a directory.")
145+
}
155146
// Add docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
156147
inputs.dir(docsDir)
157148
systemProperty("DOCS_DIR", docsDir.absolutePath)
@@ -215,10 +206,7 @@ gradlePlugin {
215206
}
216207
}
217208

218-
testSourceSets(
219-
sourceSets["functionalTest"],
220-
sourceSets["documentTest"],
221-
)
209+
testSourceSets(sourceSets["functionalTest"], sourceSets["documentTest"])
222210
}
223211

224212
// This part should be placed after testing.suites to ensure the test sourceSets are created.
@@ -234,11 +222,7 @@ tasks.withType<JavaCompile>().configureEach {
234222
options.release = libs.versions.jdkRelease.get().toInt()
235223
}
236224

237-
tasks.pluginUnderTestMetadata {
238-
pluginClasspath.from(
239-
testPluginClasspath,
240-
)
241-
}
225+
tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }
242226

243227
tasks.validatePlugins {
244228
// TODO: https://github.com/gradle/gradle/issues/22600
@@ -254,11 +238,12 @@ tasks.check {
254238
}
255239

256240
tasks.clean {
257-
delete += listOf(
258-
projectDir.resolve(".gradle"),
259-
projectDir.resolve(".kotlin"),
260-
dokka.dokkaPublications.html.map { it.outputDirectory },
261-
// Generated by MkDocs.
262-
rootDir.resolve("site"),
263-
)
241+
delete +=
242+
listOf(
243+
projectDir.resolve(".gradle"),
244+
projectDir.resolve(".kotlin"),
245+
dokka.dokkaPublications.html.map { it.outputDirectory },
246+
// Generated by MkDocs.
247+
rootDir.resolve("site"),
248+
)
264249
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pluginPublish = { module = "com.gradle.publish:plugin-publish-plugin", version.r
3030

3131
androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha05"
3232
# Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless.
33-
ktlint = "com.pinterest.ktlint:ktlint-cli:1.8.0"
33+
ktfmt = "com.facebook:ktfmt:0.59"
3434

3535
junit-bom = "org.junit:junit-bom:6.0.1"
3636
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"

settings.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ pluginManagement {
1212
}
1313
}
1414

15-
plugins {
16-
id("com.gradle.develocity") version "4.3"
17-
}
15+
plugins { id("com.gradle.develocity") version "4.3" }
1816

1917
develocity {
2018
buildScan {

src/documentTest/kotlin/com/github/jengelman/gradle/plugins/shadow/DocCodeSnippetTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ class DocCodeSnippetTest {
1212

1313
@TestFactory
1414
fun provideDynamicTests(@TempDir root: Path): List<DynamicTest> {
15-
val langExecutables = DslLang.entries.map { executor ->
16-
CodeSnippetExtractor.extract(executor)
17-
}
15+
val langExecutables = DslLang.entries.map { executor -> CodeSnippetExtractor.extract(executor) }
1816

19-
check(langExecutables.sumOf { it.size } > 0) {
20-
"No code snippets found."
21-
}
17+
check(langExecutables.sumOf { it.size } > 0) { "No code snippets found." }
2218
check(langExecutables.size == DslLang.entries.size) {
2319
"We must provide build script snippets for all languages."
2420
}

src/documentTest/kotlin/com/github/jengelman/gradle/plugins/shadow/snippet/CodeSnippetExtractor.kt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,21 @@ object CodeSnippetExtractor {
1313
private val docRoot = Path(System.getProperty("DOCS_DIR"))
1414

1515
@OptIn(ExperimentalPathApi::class)
16-
private val markdownPaths = docRoot.walk()
17-
.filter { it.name.endsWith(".md", ignoreCase = true) }
18-
.toList()
16+
private val markdownPaths =
17+
docRoot.walk().filter { it.name.endsWith(".md", ignoreCase = true) }.toList()
1918

2019
fun extract(lang: DslLang): List<SnippetExecutable> {
21-
return markdownPaths.flatMap { path ->
22-
createExecutables(lang, path)
23-
}
20+
return markdownPaths.flatMap { path -> createExecutables(lang, path) }
2421
}
2522

26-
private fun createExecutables(
27-
lang: DslLang,
28-
markdownPath: Path,
29-
): List<SnippetExecutable> {
23+
private fun createExecutables(lang: DslLang, markdownPath: Path): List<SnippetExecutable> {
3024
val relativeDocPath = markdownPath.relativeTo(docRoot).toString()
3125
return createSnippets(markdownPath.readText(), lang).map { (lineNumber, snippet) ->
32-
SnippetExecutable.create(
33-
lang,
34-
snippet,
35-
"$relativeDocPath:$lineNumber",
36-
) {
37-
RuntimeException("The error line in the doc is near ${markdownPath.toUri()}:$lineNumber", it)
26+
SnippetExecutable.create(lang, snippet, "$relativeDocPath:$lineNumber") {
27+
RuntimeException(
28+
"The error line in the doc is near ${markdownPath.toUri()}:$lineNumber",
29+
it,
30+
)
3831
}
3932
}
4033
}

src/documentTest/kotlin/com/github/jengelman/gradle/plugins/shadow/snippet/DslLang.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.snippet
22

33
enum class DslLang {
44
Kotlin,
5-
Groovy,
6-
;
5+
Groovy;
76

87
override fun toString(): String = name.lowercase()
98
}

src/documentTest/kotlin/com/github/jengelman/gradle/plugins/shadow/snippet/GroovyBuildExecutable.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ class GroovyBuildExecutable(
1010

1111
override val buildScriptName: String = "build.gradle"
1212

13-
override val pluginsBlock: String = """
13+
override val pluginsBlock: String =
14+
"""
1415
plugins {
1516
id 'java'
1617
id 'com.gradleup.shadow'
1718
}
18-
""".trimIndent()
19+
"""
20+
.trimIndent()
1921

20-
override val assembleDependsOn: String = """
22+
override val assembleDependsOn: String =
23+
"""
2124
tasks.named('assemble') {
2225
dependsOn tasks.withType(Jar) // ShadowJar is a subtype of Jar.
2326
}
24-
""".trimIndent()
27+
"""
28+
.trimIndent()
2529
}

src/documentTest/kotlin/com/github/jengelman/gradle/plugins/shadow/snippet/KotlinBuildExecutable.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ class KotlinBuildExecutable(
1010

1111
override val buildScriptName: String = "build.gradle.kts"
1212

13-
override val pluginsBlock: String = """
13+
override val pluginsBlock: String =
14+
"""
1415
plugins {
1516
java
1617
id("com.gradleup.shadow")
1718
}
18-
""".trimIndent()
19+
"""
20+
.trimIndent()
1921

20-
override val assembleDependsOn: String = """
22+
override val assembleDependsOn: String =
23+
"""
2124
tasks.named("assemble") {
2225
dependsOn(tasks.withType(Jar::class.java)) // ShadowJar is a subtype of Jar.
2326
}
24-
""".trimIndent()
27+
"""
28+
.trimIndent()
2529
}

0 commit comments

Comments
 (0)