Skip to content

Commit

Permalink
spotless plugin impl
Browse files Browse the repository at this point in the history
  • Loading branch information
nishkarsh800 committed Aug 3, 2023
1 parent 97807e9 commit 5c62a50
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mockk = "1.13.5"
com-squareup-retrofit2 = "2.6.4"
androidx-test-espresso = "3.4.0"
truth = "1.1.3"
spotless = "3.13.0"

[libraries]
# Gradle Plugins
Expand All @@ -36,6 +37,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 @@ -230,3 +234,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()
}
}

0 comments on commit 5c62a50

Please sign in to comment.