Implement Mihon's spotless PR (#1257)
* Remove detekt (mihonapp/mihon#1130) Annoying. More annoying in this project. (cherry picked from commit 777ae2461e1eb277a3aa0c998ff69e4f100387a1) * Add spotless (with ktlint) (mihonapp/mihon#1136) (cherry picked from commit 5ae8095ef1ed2ae9f98486f9148e933c77a28692) * Address spotless lint errors (mihonapp/mihon#1138) * Add spotless (with ktlint) * Run spotlessApply * screaming case screaming case screaming case * Update PagerViewerAdapter.kt * Update ReaderTransitionView.kt (cherry picked from commit d6252ab7703d52ecf9f43de3ee36fd63e665a31f) * Generate locales_config.xml in build dir (cherry picked from commit ac41bffdc97b4cfed923de6b9e8e01cccf3eb6eb) * Address more spotless lint errors in SY * some more missed * more missed * still missing, not sure while it won't report error when running locally * one more * more * more * correct comment --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,7 @@ dependencies {
|
||||
implementation(androidx.gradle)
|
||||
implementation(kotlinx.gradle)
|
||||
implementation(kotlinx.compose.compiler.gradle)
|
||||
implementation(libs.detekt.gradlePlugin)
|
||||
implementation(libs.spotless.gradle)
|
||||
implementation(gradleApi())
|
||||
|
||||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
|
||||
@@ -3,6 +3,8 @@ import mihon.buildlogic.configureCompose
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
kotlin("android")
|
||||
|
||||
id("mihon.code.lint")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -3,9 +3,10 @@ import mihon.buildlogic.configureAndroid
|
||||
import mihon.buildlogic.configureTest
|
||||
|
||||
plugins {
|
||||
id("mihon.code.detekt")
|
||||
id("com.android.application")
|
||||
kotlin("android")
|
||||
|
||||
id("mihon.code.lint")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -2,9 +2,10 @@ import mihon.buildlogic.configureAndroid
|
||||
import mihon.buildlogic.configureTest
|
||||
|
||||
plugins {
|
||||
id("mihon.code.detekt")
|
||||
id("com.android.test")
|
||||
kotlin("android")
|
||||
|
||||
id("mihon.code.lint")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import io.gitlab.arturbosch.detekt.Detekt
|
||||
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
|
||||
plugins {
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
val libs = the<LibrariesForLibs>()
|
||||
dependencies {
|
||||
detektPlugins(libs.detekt.rules.formatting)
|
||||
detektPlugins(libs.detekt.rules.compose)
|
||||
}
|
||||
|
||||
private val configFile = files("$rootDir/config/detekt/detekt.yml")
|
||||
private val baselineFile = file("$rootDir/config/detekt/baseline.xml")
|
||||
private val kotlinFiles = "**/*.kt"
|
||||
private val resourceFiles = "**/resources/**"
|
||||
private val buildFiles = "**/build/**"
|
||||
private val generatedFiles = "**/generated/**"
|
||||
private val scriptsFiles = "**/*.kts"
|
||||
|
||||
detekt {
|
||||
buildUponDefaultConfig = true
|
||||
parallel = true
|
||||
autoCorrect = false
|
||||
ignoreFailures = false
|
||||
config.setFrom(configFile)
|
||||
baseline = file(baselineFile)
|
||||
}
|
||||
|
||||
val detektProjectBaseline by tasks.registering(DetektCreateBaselineTask::class) {
|
||||
description = "Overrides current baseline."
|
||||
buildUponDefaultConfig.set(true)
|
||||
ignoreFailures.set(true)
|
||||
parallel.set(true)
|
||||
setSource(files(rootDir))
|
||||
config.setFrom(configFile)
|
||||
baseline = file(baselineFile)
|
||||
include(kotlinFiles)
|
||||
exclude(resourceFiles, buildFiles, generatedFiles, scriptsFiles)
|
||||
}
|
||||
|
||||
tasks.withType<Detekt>().configureEach {
|
||||
include(kotlinFiles)
|
||||
exclude(resourceFiles, buildFiles, generatedFiles, scriptsFiles)
|
||||
reports {
|
||||
html.required.set(true)
|
||||
xml.required.set(false)
|
||||
txt.required.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Detekt>().configureEach {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
tasks.withType<DetektCreateBaselineTask>().configureEach {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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",
|
||||
"ktlint_standard_max-line-length" to "disabled",
|
||||
"ktlint_standard_type-argument-comment" to "disabled",
|
||||
"ktlint_standard_value-argument-comment" to "disabled",
|
||||
"ktlint_standard_value-parameter-comment" to "disabled",
|
||||
))
|
||||
trimTrailingWhitespace()
|
||||
endWithNewline()
|
||||
}
|
||||
format("xml") {
|
||||
target("**/*.xml")
|
||||
targetExclude("**/build/**/*.xml")
|
||||
trimTrailingWhitespace()
|
||||
endWithNewline()
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import mihon.buildlogic.configureCompose
|
||||
|
||||
plugins {
|
||||
id("mihon.code.detekt")
|
||||
id("com.android.library")
|
||||
|
||||
id("mihon.code.lint")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -2,8 +2,9 @@ import mihon.buildlogic.configureAndroid
|
||||
import mihon.buildlogic.configureTest
|
||||
|
||||
plugins {
|
||||
id("mihon.code.detekt")
|
||||
id("com.android.library")
|
||||
|
||||
id("mihon.code.lint")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.gradle.kotlin.dsl.the
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.File
|
||||
|
||||
val Project.androidx get() = the<LibrariesForAndroidx>()
|
||||
val Project.compose get() = the<LibrariesForCompose>()
|
||||
@@ -106,3 +107,5 @@ internal fun Project.configureTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Project.generatedBuildDir: File get() = project.layout.buildDirectory.asFile.get().resolve("generated/mihon")
|
||||
|
||||
@@ -3,10 +3,11 @@ package mihon.buildlogic.tasks
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import java.io.File
|
||||
|
||||
private val emptyResourcesElement = "<resources>\\s*</resources>|<resources/>".toRegex()
|
||||
private val emptyResourcesElement = "<resources>\\s*</resources>|<resources\\s*/>".toRegex()
|
||||
|
||||
fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
||||
fun Project.getLocalesConfigTask(outputResourceDir: File): TaskProvider<Task> {
|
||||
return tasks.register("generateLocalesConfig") {
|
||||
val locales = fileTree("$projectDir/src/commonMain/moko-resources/")
|
||||
.matching { include("**/strings.xml") }
|
||||
@@ -16,7 +17,6 @@ fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
||||
.replace("base", "en")
|
||||
.replace("-r", "-")
|
||||
.replace("+", "-")
|
||||
.takeIf(String::isNotBlank) ?: "en"
|
||||
}
|
||||
.sorted()
|
||||
.joinToString("\n") { "| <locale android:name=\"$it\"/>" }
|
||||
@@ -28,10 +28,9 @@ fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
||||
|</locale-config>
|
||||
""".trimMargin()
|
||||
|
||||
file("$projectDir/src/androidMain/res/xml/locales_config.xml").apply {
|
||||
outputResourceDir.resolve("xml/locales_config.xml").apply {
|
||||
parentFile.mkdirs()
|
||||
writeText(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user