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

spotless plugin for code formatting #5056

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
alias(libs.plugins.dokka)

}

fun obtainTestBuildType(): String {
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ buildscript {
classpath(libs.plugin.gradle.greendao)
classpath(libs.plugin.gradle.hilt)
classpath(libs.plugin.gradle.kotlin)
classpath(libs.plugin.gradle.spotless)
}
}

Expand All @@ -33,6 +34,7 @@ plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.versions)
alias(libs.plugins.updates)
alias(libs.plugins.format)
}

allprojects {
Expand Down
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mockk = "1.13.5"
com-squareup-retrofit2 = "2.6.4"
androidx-test-espresso = "3.4.0"
truth = "1.1.3"
ui = "1.4.3"


[libraries]
# Gradle Plugins
Expand All @@ -38,6 +38,9 @@ plugin-gradle-hilt = { module = "com.google.dagger:hilt-android-gradle-plugin",
# https://kotlinlang.org/docs/gradle.html
plugin-gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }

plugin-gradle-spotless = {module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless"}


# Coroutines
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" }
kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlin-coroutines" }
Expand Down Expand Up @@ -253,3 +256,5 @@ sonarqube = "org.sonarqube:4.2.0.3129"
detekt = "io.gitlab.arturbosch.detekt:1.20.0"
versions = "com.github.ben-manes.versions:0.41.0"
updates = "nl.littlerobots.version-catalog-update:0.5.1"
format = "com.diffplug.gradle.spotless: 3.13.0"

61 changes: 61 additions & 0 deletions spotless.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apply plugin: 'com.diffplug.spotless'

ext {
ci = System.getenv("CI") == "true"
ktlintVersion = "0.30.0"
spotlessVersion = "3.13.0"
}
spotless {
if (ci) {
ratchetFrom null
} else {
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom 'origin/develop'
}


format 'misc', {
// define the files to apply `misc` to
target '**/*.gradle', '**/*.md', '**/.gitignore'

// define the steps to apply to those files
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}

kotlin {
target '**/*.kt'

def map = [
"ktlint_standard_package-name": "disabled",
"ktlint_standard_no-wildcard-imports" :"disabled",
"ktlint_standard_no-semi" : "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" : "disabled",
"ktlint_standard_trailing-comma-on-call-site" : "disabled"
]
ktlint("0.48.2")
.setUseExperimental(false)
.userData(["android" : "true"])
.editorConfigOverride(map)
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}

java {
target 'src/*/java/**/*.java'
googleJavaFormat().aosp()
removeUnusedImports()
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}

format 'xml', {
target 'src/**/*/xml' // target only xml files in src folders
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
Loading