Skip to content

Commit 8dfb84c

Browse files
authored
feat: introduce spotless/ktlint (#39)
* feat: introduce spotless + ktlint * chore: run `spotlessApply` to format the code * chore: exclude `examples` module * fix: PROJECT_VERSION variable name * fix: remove @Preview from Gallery * chore: fix conflict * build: add spotless CI * chore: run spotlessApply to format the code * build: remove examples module from settings.gradle.kts configuration * chore: remove detekt.yml * refactor: change the project indentation to 4 spaces
1 parent c9735c0 commit 8dfb84c

File tree

91 files changed

+2705
-2781
lines changed

Some content is hidden

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

91 files changed

+2705
-2781
lines changed

Diff for: .editorconfig

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.{kt,kts}]
11+
ij_kotlin_imports_layout = *
12+
ij_kotlin_allow_trailing_comma = true
13+
ij_kotlin_allow_trailing_comma_on_call_site = true
14+
ij_kotlin_line_break_after_multiline_when_entry = false
15+
ij_kotlin_name_count_to_use_star_import = 2147483647
16+
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
17+
ij_kotlin_packages_to_use_import_on_demand = unset
18+
ktlint_code_style = intellij_idea
19+
ktlint_function_naming_ignore_when_annotated_with = Composable
20+
ktlint_standard_function-expression-body = disabled
21+
ktlint_standard_filename = disabled
22+
ktlint_compose_modifier-missing-check = disabled
23+
24+
[*.md]
25+
trim_trailing_whitespace = false
26+
27+
[*.xml]
28+
indent_size = 4

Diff for: .github/workflows/spotless.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Spotless Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
spotless:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up JDK
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
cache: gradle
22+
23+
- name: Grant execute permission for gradlew
24+
run: chmod +x ./gradlew
25+
26+
- name: Run Spotless Check
27+
run: ./gradlew spotlessCheck

Diff for: build.gradle.kts

+51-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
1+
import com.diffplug.gradle.spotless.SpotlessExtension
2+
13
plugins {
2-
// this is necessary to avoid the plugins to be loaded multiple times
3-
// in each subproject's classloader
4-
alias(libs.plugins.androidApplication) apply false
5-
alias(libs.plugins.androidLibrary) apply false
6-
alias(libs.plugins.jetbrainsCompose) apply false
7-
alias(libs.plugins.kotlinMultiplatform) apply false
8-
alias(libs.plugins.compose.compiler) apply false
9-
alias(libs.plugins.kotlin.jvm) apply false
10-
alias(libs.plugins.dokka) apply false
4+
// this is necessary to avoid the plugins to be loaded multiple times
5+
// in each subproject's classloader
6+
alias(libs.plugins.androidApplication) apply false
7+
alias(libs.plugins.androidLibrary) apply false
8+
alias(libs.plugins.jetbrainsCompose) apply false
9+
alias(libs.plugins.kotlinMultiplatform) apply false
10+
alias(libs.plugins.compose.compiler) apply false
11+
alias(libs.plugins.kotlin.jvm) apply false
12+
alias(libs.plugins.dokka) apply false
13+
alias(libs.plugins.spotless) apply false
1114
}
1215

1316
subprojects {
14-
version = findProperty("storytale.deploy.version")
15-
?: error("'storytale.deploy.version' was not set")
17+
version = findProperty("storytale.deploy.version")
18+
?: error("'storytale.deploy.version' was not set")
1619

17-
plugins.withId("maven-publish") {
18-
configureIfExists<PublishingExtension> {
19-
repositories {
20-
maven {
21-
name = "ComposeRepo"
22-
setUrl(System.getenv("COMPOSE_REPO_URL"))
23-
credentials {
24-
username = System.getenv("COMPOSE_REPO_USERNAME")
25-
password = System.getenv("COMPOSE_REPO_KEY")
26-
}
20+
plugins.withId("maven-publish") {
21+
configureIfExists<PublishingExtension> {
22+
repositories {
23+
maven {
24+
name = "ComposeRepo"
25+
setUrl(System.getenv("COMPOSE_REPO_URL"))
26+
credentials {
27+
username = System.getenv("COMPOSE_REPO_USERNAME")
28+
password = System.getenv("COMPOSE_REPO_KEY")
29+
}
30+
}
31+
}
32+
}
33+
}
34+
plugins.apply(rootProject.libs.plugins.spotless.get().pluginId)
35+
extensions.configure<SpotlessExtension> {
36+
kotlin {
37+
target("src/**/*.kt")
38+
targetExclude("src/test/resources/**")
39+
ktlint(libs.ktlint.get().version)
40+
.editorConfigOverride(
41+
mapOf(
42+
"indent_size" to "4",
43+
"ktlint_compose_modifier-missing-check" to "disabled",
44+
"ktlint_compose_compositionlocal-allowlist" to "disabled",
45+
),
46+
)
47+
.customRuleSets(listOf(libs.composeRules.get().toString()))
48+
}
49+
kotlinGradle {
50+
target("*.gradle.kts")
51+
ktlint(libs.ktlint.get().version)
52+
.editorConfigOverride(
53+
mapOf("indent_size" to "4"),
54+
)
2755
}
28-
}
2956
}
30-
}
3157
}
3258

3359
inline fun <reified T> Project.configureIfExists(fn: T.() -> Unit) {
34-
extensions.findByType(T::class.java)?.fn()
35-
}
60+
extensions.findByType(T::class.java)?.fn()
61+
}

Diff for: detekt.yml

-221
This file was deleted.

Diff for: examples/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ kotlin {
4040
listOf(
4141
iosX64(),
4242
iosArm64(),
43-
iosSimulatorArm64()
43+
iosSimulatorArm64(),
4444
).forEach { iosTarget ->
4545
iosTarget.binaries.framework {
4646
baseName = "ComposeApp"

Diff for: examples/src/androidMain/kotlin/Platform.android.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ class AndroidPlatform : Platform {
44
override val name: String = "Android ${Build.VERSION.SDK_INT}"
55
}
66

7-
actual fun getPlatform(): Platform = AndroidPlatform()
7+
actual fun getPlatform(): Platform = AndroidPlatform()

Diff for: examples/src/androidMain/kotlin/org/jetbrains/storytale/example/MainActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class MainActivity : ComponentActivity() {
1919

2020
@Preview
2121
@Composable
22-
fun AppAndroidPreview() {
22+
private fun AppAndroidPreview() {
2323
App()
24-
}
24+
}

0 commit comments

Comments
 (0)