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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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 = 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use 4 spaces, as suggested by the official convention - https://kotlinlang.org/docs/coding-conventions.html#indentation ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! but for the compose project, I might prefer 2 spaces for indentation, as it looks more readable in cases with deep component nesting. However, if 4 spaces are to be used, that's fine too

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.
One more argument for keeping it 4 is that the repository is in Kotlin group, so using the official convention is preferred :)

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
24 changes: 23 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.diffplug.gradle.spotless.SpotlessExtension

plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
Expand All @@ -8,6 +10,7 @@ plugins {
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 {
Expand All @@ -28,8 +31,27 @@ subprojects {
}
}
}
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(
"ktlint_compose_modifier-missing-check" to "disabled",
"ktlint_compose_compositionlocal-allowlist" to "disabled",
),
)
.customRuleSets(listOf(libs.composeRules.get().toString()))
}
kotlinGradle {
ktlint(libs.ktlint.get().version)
}
}
}

inline fun <reified T> Project.configureIfExists(fn: T.() -> Unit) {
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()
}
}
22 changes: 15 additions & 7 deletions examples/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import org.jetbrains.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
@Preview
fun App() {
fun App(modifier: Modifier = Modifier) {
var showContent by remember { mutableStateOf(false) }

MaterialTheme {
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Column(
modifier = modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
PrimaryButton(text = "Click Me", onClick = { showContent = !showContent })
AnimatedVisibility(showContent) {
val greeting = remember { Greeting().greet() }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
ComposeLogo()
ComposeLogo(Modifier.size(600.dp))
Text("Compose: $greeting")
}
}
}
}
}
}
Loading