From 7914b26488cfe941902744b3f7f45fabe9687cc1 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Thu, 25 Mar 2021 14:55:59 -0400 Subject: [PATCH] Adding kotlinter --- app/build.gradle.kts | 28 ++++- build.gradle.kts | 24 +--- buildSrc/src/main/kotlin/Dependencies.kt | 4 +- ktlintCodeStyle.xml | 136 +++++++++++++++++++++++ 4 files changed, 170 insertions(+), 22 deletions(-) create mode 100644 ktlintCodeStyle.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cfb8c807fd..540b8608f3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -264,8 +264,32 @@ dependencies { implementation("org.conscrypt:conscrypt-android:2.4.0") } -tasks.preBuild { - dependsOn(tasks.ktlintFormat) + + +tasks { + // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers) + withType { + kotlinOptions.freeCompilerArgs += listOf( + "-Xopt-in=kotlin.Experimental", + "-Xopt-in=kotlin.RequiresOptIn", + "-Xuse-experimental=kotlin.ExperimentalStdlibApi", + "-Xuse-experimental=kotlinx.coroutines.FlowPreview", + "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", + "-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi", + "-Xuse-experimental=kotlinx.serialization.ExperimentalSerializationApi" + ) + } + + // Duplicating Hebrew string assets due to some locale code issues on different devices + val copyHebrewStrings = task("copyHebrewStrings", type = Copy::class) { + from("./src/main/res/values-he") + into("./src/main/res/values-iw") + include("**/*") + } + + preBuild { + dependsOn(formatKotlin, copyHebrewStrings) + } } if (gradle.startParameter.taskRequests.toString().contains("Standard")) { diff --git a/build.gradle.kts b/build.gradle.kts index a310eec25a..6e09699e7d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,5 @@ -import Versions.ktlint - plugins { - id(Plugins.ktLint.name) version Plugins.ktLint.version + id(Plugins.kotlinter.name) version Plugins.kotlinter.version id(Plugins.gradleVersions.name) version Plugins.gradleVersions.version } allprojects { @@ -15,22 +13,10 @@ allprojects { } subprojects { - apply(plugin = Plugins.ktLint.name) - ktlint { - debug.set(true) - verbose.set(true) - android.set(false) - outputToConsole.set(true) - ignoreFailures.set(true) - enableExperimentalRules.set(false) - reporters { - reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE) - reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.JSON) - } - filter { - exclude("**/generated/**") - include("**/kotlin/**") - } + apply(plugin = Plugins.kotlinter.name) + + kotlinter { + experimentalRules = true } } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 6509fe4f17..f2261c47f0 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -91,6 +91,7 @@ object Versions { const val viewStatePagerAdapter = "1.1.0" const val viewToolTip = "1.2.2" const val xlog = "1.6.1" + const val kotlinter = "3.4.0" } object LegacyPluginClassPath { @@ -124,6 +125,7 @@ object Plugins { const val kotlinSerialization = "org.jetbrains.kotlin.plugin.serialization" val gradleVersions = PluginClass("com.github.ben-manes.versions", Versions.gradleVersions) val ktLint = PluginClass("org.jlleitschuh.gradle.ktlint", Versions.ktlint) + val kotlinter = PluginClass("org.jmailen.kotlinter", Versions.kotlinter) } data class PluginClass(val name: String, val version: String) @@ -144,7 +146,7 @@ object BuildPluginsVersion { const val KOTLIN = "1.4.10" const val ANDROID_EXTENSIONS = "org.jetbrains.kotlin:kotlin-android-extensions:$KOTLIN" const val KOTLIN_GRADLE = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN" - const val KOTLINTER = "org.jmailen.gradle:kotlinter-gradle:3.0.2" + const val KOTLINTER = "3.3.0" const val GOOGLE_SERVICES = "com.google.gms:google-services:4.3.3" const val OSS_LICENSE = "com.google.android.gms:oss-licenses-plugin:0.10.2" const val VERSIONS_PLUGIN = "0.28.0" diff --git a/ktlintCodeStyle.xml b/ktlintCodeStyle.xml new file mode 100644 index 0000000000..e1422c7c8f --- /dev/null +++ b/ktlintCodeStyle.xml @@ -0,0 +1,136 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
\ No newline at end of file