From d369a63faf4d7e55ec542277e43cbbf81d23be41 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:38:03 -0500 Subject: [PATCH] refactor(spotless): configure spotless via editorconfig (#2513) Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> --- app/build.gradle.kts | 56 ++++++++++++++--------------- config/spotless/.editorconfig | 15 ++++++++ config/{ => spotless}/copyright.txt | 0 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 config/spotless/.editorconfig rename config/{ => spotless}/copyright.txt (100%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 66cae87d0..a6fac10da 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -103,7 +103,7 @@ android { "zh-rCN", "zh-rTW", "uk", - ) + ), ) ndk { abiFilters += listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64") } } @@ -118,8 +118,18 @@ android { create("google") { dimension = "default" // Enable Firebase Crashlytics for Google Play builds - apply(plugin = libs.plugins.google.services.get().pluginId) - apply(plugin = libs.plugins.firebase.crashlytics.get().pluginId) + apply( + plugin = + libs.plugins.google.services + .get() + .pluginId, + ) + apply( + plugin = + libs.plugins.firebase.crashlytics + .get() + .pluginId, + ) versionName = "${Configs.VERSION_NAME_BASE} ($versionCode) google" } } @@ -168,7 +178,12 @@ kotlin { // per protobuf-gradle-plugin docs, this is recommended for android protobuf { - protoc { artifact = libs.protobuf.protoc.get().toString() } + protoc { + artifact = + libs.protobuf.protoc + .get() + .toString() + } generateProtoTasks { all().forEach { task -> task.builtins { @@ -267,9 +282,8 @@ detekt { val googleServiceKeywords = listOf("crashlytics", "google") tasks.configureEach { - if ( - googleServiceKeywords.any { name.contains(it, ignoreCase = true) } && - name.contains("fdroid", ignoreCase = true) + if (googleServiceKeywords.any { name.contains(it, ignoreCase = true) } && + name.contains("fdroid", ignoreCase = true) ) { project.logger.lifecycle("Disabling task for F-Droid: $name") enabled = false @@ -281,31 +295,13 @@ spotless { kotlin { target("src/*/kotlin/**/*.kt", "src/*/java/**/*.kt") targetExclude("**/build/**/*.kt") - ktlint() - .editorConfigOverride( - mapOf("ktlint_function_naming_ignore_when_annotated_with" to "Composable") - ) - ktfmt().kotlinlangStyle() - licenseHeaderFile(rootProject.file("config/copyright.txt")) + ktfmt() + ktlint("1.7.1").setEditorConfigPath("../config/spotless/.editorconfig") + licenseHeaderFile(rootProject.file("config/spotless/copyright.txt")) } kotlinGradle { target("**/*.gradle.kts") - ktlint() - ktfmt().kotlinlangStyle() + ktfmt() + ktlint("1.7.1").setEditorConfigPath("../config/spotless/.editorconfig") } } - -tasks.register("createSpotlessPreCommitHook") { - val gitHooksDirectory = rootProject.file(".git/hooks") - if (!gitHooksDirectory.exists()) gitHooksDirectory.mkdirs() - val preCommitHook = rootProject.file(".git/hooks/pre-commit") - preCommitHook.writeText( - """ - #!/bin/bash - echo "Running spotless check" - ./gradlew spotlessApply - """ - .trimIndent() - ) - preCommitHook.setExecutable(true) -} diff --git a/config/spotless/.editorconfig b/config/spotless/.editorconfig new file mode 100644 index 000000000..c8b95c210 --- /dev/null +++ b/config/spotless/.editorconfig @@ -0,0 +1,15 @@ +[*.{kt,kts}] +ktlint_code_style = ktlint_official +ktlint_standard = enabled +ktlint_experimental = enabled +ktlint_custom_rule-set = enabled +ktlint_function_naming_ignore_when_annotated_with = Composable + +root = true +ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL +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 + +[*] +insert_final_newline = true \ No newline at end of file diff --git a/config/copyright.txt b/config/spotless/copyright.txt similarity index 100% rename from config/copyright.txt rename to config/spotless/copyright.txt