Skip to content

Commit

Permalink
Add spotless (with ktlint)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntsyLich committed Aug 19, 2024
1 parent 777ae24 commit ed37d86
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build app and run unit tests
run: ./gradlew assembleStandardRelease testReleaseUnitTest testStandardReleaseUnitTest
run: ./gradlew spotlessCheck assembleStandardRelease testReleaseUnitTest testStandardReleaseUnitTest

- name: Upload APK
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build app and run unit tests
run: ./gradlew assembleStandardRelease testReleaseUnitTest testStandardReleaseUnitTest
run: ./gradlew spotlessCheck assembleStandardRelease testReleaseUnitTest testStandardReleaseUnitTest

- name: Upload APK
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies {
implementation(androidx.gradle)
implementation(kotlinx.gradle)
implementation(kotlinx.compose.compiler.gradle)
implementation(libs.spotless.gradle)
implementation(gradleApi())

implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import mihon.buildlogic.configureCompose
plugins {
id("com.android.application")
kotlin("android")

id("mihon.code.lint")
}

android {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/mihon.android.application.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import mihon.buildlogic.configureTest
plugins {
id("com.android.application")
kotlin("android")

id("mihon.code.lint")
}

android {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/mihon.benchmark.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import mihon.buildlogic.configureTest
plugins {
id("com.android.test")
kotlin("android")

id("mihon.code.lint")
}

android {
Expand Down
30 changes: 30 additions & 0 deletions buildSrc/src/main/kotlin/mihon.code.lint.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import org.gradle.accessors.dm.LibrariesForLibs

plugins {
id("com.diffplug.spotless")
}

val libs = the<LibrariesForLibs>()

spotless {
kotlin {
target("**/*.kt", "**/*.kts")
targetExclude("**/build/**/*.kt")
ktlint(libs.ktlint.core.get().version)
.editorConfigOverride(mapOf(
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
"ktlint_standard_class-signature" to "disabled",
"ktlint_standard_discouraged-comment-location" to "disabled",
"ktlint_standard_function-expression-body" to "disabled",
"ktlint_standard_function-signature" to "disabled",
))
trimTrailingWhitespace()
endWithNewline()
}
format("xml") {
target("**/*.xml")
targetExclude("**/build/**/*.xml")
trimTrailingWhitespace()
endWithNewline()
}
}
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/mihon.library.compose.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import mihon.buildlogic.configureCompose

plugins {
id("com.android.library")

id("mihon.code.lint")
}

android {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/mihon.library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import mihon.buildlogic.configureTest

plugins {
id("com.android.library")

id("mihon.code.lint")
}

android {
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ shizuku_version = "12.2.0"
sqldelight = "2.0.2"
sqlite = "2.4.0"
voyager = "1.0.0"
spotless = "6.25.0"
ktlint-core = "1.3.1"

[libraries]
desugar = "com.android.tools:desugar_jdk_libs:2.0.4"
Expand Down Expand Up @@ -96,6 +98,9 @@ voyager-screenmodel = { module = "cafe.adriel.voyager:voyager-screenmodel", vers
voyager-tab-navigator = { module = "cafe.adriel.voyager:voyager-tab-navigator", version.ref = "voyager" }
voyager-transitions = { module = "cafe.adriel.voyager:voyager-transitions", version.ref = "voyager" }

spotless-gradle = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" }
ktlint-core = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint-core" }

[bundles]
okhttp = ["okhttp-core", "okhttp-logging", "okhttp-brotli", "okhttp-dnsoverhttps"]
js-engine = ["quickjs-android"]
Expand Down

0 comments on commit ed37d86

Please sign in to comment.