Skip to content

Commit ff63b9a

Browse files
committed
feat: add ktfmt-gradle plugin for consistent formatting
Can be invoked via `gradlew ktfmtCheck` and `gradlew ktfmtFormat`
1 parent cf35033 commit ff63b9a

File tree

3 files changed

+69
-74
lines changed

3 files changed

+69
-74
lines changed

build.gradle.kts

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,91 +10,98 @@ plugins {
1010
alias(libs.plugins.changelog) // Gradle Changelog Plugin
1111
alias(libs.plugins.qodana) // Gradle Qodana Plugin
1212
alias(libs.plugins.kover) // Gradle Kover Plugin
13+
id("com.ncorti.ktfmt.gradle") version "0.24.0" // Gradle ktfmt Plugin
1314
}
1415

1516
group = providers.gradleProperty("pluginGroup").get()
17+
1618
version = providers.gradleProperty("pluginVersion").get()
1719

1820
// Set the JVM language level used to build the project.
19-
kotlin {
20-
jvmToolchain(21)
21-
}
21+
kotlin { jvmToolchain(21) }
2222

2323
// Configure project's dependencies
2424
repositories {
2525
mavenCentral()
2626

27-
// IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
28-
intellijPlatform {
29-
defaultRepositories()
30-
}
27+
// IntelliJ Platform Gradle Plugin Repositories Extension - read more:
28+
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
29+
intellijPlatform { defaultRepositories() }
3130
}
3231

33-
sourceSets {
34-
main {
35-
java {
36-
setSrcDirs(listOf("src/main/kotlin", "src/main/gen"))
37-
}
38-
}
39-
}
32+
sourceSets { main { java { setSrcDirs(listOf("src/main/kotlin", "src/main/gen")) } } }
4033

41-
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
34+
// Dependencies are managed with Gradle version catalog - read more:
35+
// https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
4236
dependencies {
4337
testImplementation(libs.junit)
4438
testImplementation(libs.opentest4j)
4539

46-
// IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
40+
// IntelliJ Platform Gradle Plugin Dependencies Extension - read more:
41+
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
4742
intellijPlatform {
48-
create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
43+
create(
44+
providers.gradleProperty("platformType"),
45+
providers.gradleProperty("platformVersion"),
46+
)
4947

50-
// Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins.
48+
// Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties
49+
// file for bundled IntelliJ Platform plugins.
5150
bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') })
5251

53-
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
52+
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for
53+
// plugin from JetBrains Marketplace.
5454
plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })
5555

56-
// Module Dependencies. Uses `platformBundledModules` property from the gradle.properties file for bundled IntelliJ Platform modules.
56+
// Module Dependencies. Uses `platformBundledModules` property from the gradle.properties
57+
// file for bundled IntelliJ Platform modules.
5758
bundledModules(providers.gradleProperty("platformBundledModules").map { it.split(',') })
5859

5960
testFramework(TestFrameworkType.Platform)
6061
}
6162
}
6263

63-
// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
64+
// Configure IntelliJ Platform Gradle Plugin - read more:
65+
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
6466
intellijPlatform {
6567
pluginConfiguration {
6668
name = providers.gradleProperty("pluginName")
6769
version = providers.gradleProperty("pluginVersion")
6870

69-
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
70-
description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
71-
val start = "<!-- Plugin description -->"
72-
val end = "<!-- Plugin description end -->"
73-
74-
with(it.lines()) {
75-
if (!containsAll(listOf(start, end))) {
76-
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
71+
// Extract the <!-- Plugin description --> section from README.md and provide for the
72+
// plugin's manifest
73+
description =
74+
providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
75+
val start = "<!-- Plugin description -->"
76+
val end = "<!-- Plugin description end -->"
77+
78+
with(it.lines()) {
79+
if (!containsAll(listOf(start, end))) {
80+
throw GradleException(
81+
"Plugin description section not found in README.md:\n$start ... $end"
82+
)
83+
}
84+
subList(indexOf(start) + 1, indexOf(end))
85+
.joinToString("\n")
86+
.let(::markdownToHTML)
7787
}
78-
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
7988
}
80-
}
8189

8290
val changelog = project.changelog // local variable for configuration cache compatibility
8391
// Get the latest available change notes from the changelog file
84-
changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion ->
85-
with(changelog) {
86-
renderItem(
87-
(getOrNull(pluginVersion) ?: getUnreleased())
88-
.withHeader(false)
89-
.withEmptySections(false),
90-
Changelog.OutputType.HTML,
91-
)
92+
changeNotes =
93+
providers.gradleProperty("pluginVersion").map { pluginVersion ->
94+
with(changelog) {
95+
renderItem(
96+
(getOrNull(pluginVersion) ?: getUnreleased())
97+
.withHeader(false)
98+
.withEmptySections(false),
99+
Changelog.OutputType.HTML,
100+
)
101+
}
92102
}
93-
}
94103

95-
ideaVersion {
96-
sinceBuild = providers.gradleProperty("pluginSinceBuild")
97-
}
104+
ideaVersion { sinceBuild = providers.gradleProperty("pluginSinceBuild") }
98105
}
99106

100107
signing {
@@ -105,44 +112,34 @@ intellijPlatform {
105112

106113
publishing {
107114
token = providers.environmentVariable("PUBLISH_TOKEN")
108-
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
109-
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
115+
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release
116+
// labels, like 2.1.7-alpha.3
117+
// Specify pre-release label to publish the plugin in a custom Release Channel
118+
// automatically. Read more:
110119
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
111-
channels = providers.gradleProperty("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
120+
channels =
121+
providers.gradleProperty("pluginVersion").map {
122+
listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" })
123+
}
112124
}
113125

114-
pluginVerification {
115-
ides {
116-
recommended()
117-
}
118-
}
126+
pluginVerification { ides { recommended() } }
119127
}
120128

121-
// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
129+
// Configure Gradle Changelog Plugin - read more:
130+
// https://github.com/JetBrains/gradle-changelog-plugin
122131
changelog {
123132
groups.empty()
124133
repositoryUrl = providers.gradleProperty("pluginRepositoryUrl")
125134
}
126135

127136
// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
128-
kover {
129-
reports {
130-
total {
131-
xml {
132-
onCheck = true
133-
}
134-
}
135-
}
136-
}
137+
kover { reports { total { xml { onCheck = true } } } }
137138

138139
tasks {
139-
wrapper {
140-
gradleVersion = providers.gradleProperty("gradleVersion").get()
141-
}
140+
wrapper { gradleVersion = providers.gradleProperty("gradleVersion").get() }
142141

143-
publishPlugin {
144-
dependsOn(patchChangelog)
145-
}
142+
publishPlugin { dependsOn(patchChangelog) }
146143
}
147144

148145
intellijPlatformTesting {
@@ -161,9 +158,9 @@ intellijPlatformTesting {
161158
}
162159
}
163160

164-
plugins {
165-
robotServerPlugin()
166-
}
161+
plugins { robotServerPlugin() }
167162
}
168163
}
169164
}
165+
166+
ktfmt { kotlinLangStyle() }

settings.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
plugins {
2-
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
3-
}
1+
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" }
42

53
rootProject.name = "tempest-phpstorm-plugin"

src/test/kotlin/com/github/tempest/framework/MyPluginTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.github.tempest.framework
22

3+
import com.github.tempest.framework.services.MyProjectService
34
import com.intellij.ide.highlighter.XmlFileType
45
import com.intellij.openapi.components.service
56
import com.intellij.psi.xml.XmlFile
67
import com.intellij.testFramework.TestDataPath
78
import com.intellij.testFramework.fixtures.BasePlatformTestCase
89
import com.intellij.util.PsiErrorElementUtil
9-
import com.github.tempest.framework.services.MyProjectService
1010

1111
@TestDataPath("\$CONTENT_ROOT/src/test/testData")
1212
class MyPluginTest : BasePlatformTestCase() {

0 commit comments

Comments
 (0)