Skip to content
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

feat: introduce spotless/ktlint #39

Merged
merged 11 commits into from
Feb 19, 2025
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_imports_layout = *
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_line_break_after_multiline_when_entry = false
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = unset
ktlint_code_style = intellij_idea
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_standard_function-expression-body = disabled
ktlint_standard_filename = disabled
ktlint_compose_modifier-missing-check = disabled

[*.md]
trim_trailing_whitespace = false

[*.xml]
indent_size = 4
27 changes: 27 additions & 0 deletions .github/workflows/spotless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Spotless Check

on:
pull_request:
branches:
- main

jobs:
spotless:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Run Spotless Check
run: ./gradlew spotlessCheck
76 changes: 51 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,61 @@
import com.diffplug.gradle.spotless.SpotlessExtension

plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.dokka) apply false
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless) apply false
}

subprojects {
version = findProperty("storytale.deploy.version")
?: error("'storytale.deploy.version' was not set")
version = findProperty("storytale.deploy.version")
?: error("'storytale.deploy.version' was not set")

plugins.withId("maven-publish") {
configureIfExists<PublishingExtension> {
repositories {
maven {
name = "ComposeRepo"
setUrl(System.getenv("COMPOSE_REPO_URL"))
credentials {
username = System.getenv("COMPOSE_REPO_USERNAME")
password = System.getenv("COMPOSE_REPO_KEY")
}
plugins.withId("maven-publish") {
configureIfExists<PublishingExtension> {
repositories {
maven {
name = "ComposeRepo"
setUrl(System.getenv("COMPOSE_REPO_URL"))
credentials {
username = System.getenv("COMPOSE_REPO_USERNAME")
password = System.getenv("COMPOSE_REPO_KEY")
}
}
}
}
}
plugins.apply(rootProject.libs.plugins.spotless.get().pluginId)
extensions.configure<SpotlessExtension> {
kotlin {
target("src/**/*.kt")
targetExclude("src/test/resources/**")
ktlint(libs.ktlint.get().version)
.editorConfigOverride(
mapOf(
"indent_size" to "4",
"ktlint_compose_modifier-missing-check" to "disabled",
"ktlint_compose_compositionlocal-allowlist" to "disabled",
),
)
.customRuleSets(listOf(libs.composeRules.get().toString()))
}
kotlinGradle {
target("*.gradle.kts")
ktlint(libs.ktlint.get().version)
.editorConfigOverride(
mapOf("indent_size" to "4"),
)
}
}
}
}
}

inline fun <reified T> Project.configureIfExists(fn: T.() -> Unit) {
extensions.findByType(T::class.java)?.fn()
}
extensions.findByType(T::class.java)?.fn()
}
221 changes: 0 additions & 221 deletions detekt.yml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ kotlin {
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
iosSimulatorArm64(),
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
Expand Down
2 changes: 1 addition & 1 deletion examples/src/androidMain/kotlin/Platform.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ class AndroidPlatform : Platform {
override val name: String = "Android ${Build.VERSION.SDK_INT}"
}

actual fun getPlatform(): Platform = AndroidPlatform()
actual fun getPlatform(): Platform = AndroidPlatform()
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class MainActivity : ComponentActivity() {

@Preview
@Composable
fun AppAndroidPreview() {
private fun AppAndroidPreview() {
App()
}
}
Loading