From 880dc85a409ccb38b4481982c20a33867ba787cf Mon Sep 17 00:00:00 2001 From: Adam McNeilly Date: Tue, 31 Jan 2023 22:43:30 -0500 Subject: [PATCH 1/2] Switching for Kotlinter for #17. --- README.md | 1 - app/build.gradle.kts | 1 + app/src/main/java/template/theme/Shape.kt | 2 +- app/src/main/java/template/theme/Theme.kt | 4 ++-- app/src/main/java/template/theme/Type.kt | 2 +- build.gradle.kts | 10 +++++----- buildscripts/ktlint.gradle | 14 -------------- documentation/StaticAnalysis.md | 6 +++--- git-hooks/pre-commit.sh | 2 +- git-hooks/pre-push.sh | 2 +- 10 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 buildscripts/ktlint.gradle diff --git a/README.md b/README.md index 2db9a8d..ea7ce12 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ You may notice that dependencies are set up in a very specific way. Each of the ```groovy subprojects { - apply from: "../buildscripts/ktlint.gradle" apply from: "../buildscripts/detekt.gradle" apply from: "../buildscripts/versionsplugin.gradle" } diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ca94c65..8b9aad5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.application") id("kotlin-android") + id("org.jmailen.kotlinter") } android { diff --git a/app/src/main/java/template/theme/Shape.kt b/app/src/main/java/template/theme/Shape.kt index d543557..f09afcd 100644 --- a/app/src/main/java/template/theme/Shape.kt +++ b/app/src/main/java/template/theme/Shape.kt @@ -7,5 +7,5 @@ import androidx.compose.ui.unit.dp val Shapes = Shapes( small = RoundedCornerShape(4.dp), medium = RoundedCornerShape(4.dp), - large = RoundedCornerShape(0.dp), + large = RoundedCornerShape(0.dp) ) diff --git a/app/src/main/java/template/theme/Theme.kt b/app/src/main/java/template/theme/Theme.kt index 54dce6b..7de7191 100644 --- a/app/src/main/java/template/theme/Theme.kt +++ b/app/src/main/java/template/theme/Theme.kt @@ -13,12 +13,12 @@ import androidx.compose.ui.platform.LocalContext private val darkColorScheme = darkColorScheme( primary = Purple200, - secondary = Teal200, + secondary = Teal200 ) private val lightColorScheme = lightColorScheme( primary = Purple500, - secondary = Teal200, + secondary = Teal200 ) @Composable diff --git a/app/src/main/java/template/theme/Type.kt b/app/src/main/java/template/theme/Type.kt index 0177a3f..aba9e25 100644 --- a/app/src/main/java/template/theme/Type.kt +++ b/app/src/main/java/template/theme/Type.kt @@ -12,5 +12,5 @@ val Typography = Typography( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp - ), + ) ) diff --git a/build.gradle.kts b/build.gradle.kts index ceb78ba..0fad0da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,9 +3,6 @@ buildscript { extra.apply { set("kotlinVersion", "1.7.10") - // https://github.com/JLLeitschuh/ktlint-gradle/releases - set("ktlintPluginVersion", "11.0.0") - // https://github.com/detekt/detekt/releases set("detektVersion", "1.21.0") @@ -22,7 +19,6 @@ buildscript { dependencies { classpath("com.android.tools.build:gradle:7.2.2") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra.get("kotlinVersion")}") - classpath("org.jlleitschuh.gradle:ktlint-gradle:${rootProject.extra.get("ktlintPluginVersion")}") classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${rootProject.extra.get("detektVersion")}") classpath("com.github.ben-manes:gradle-versions-plugin:${rootProject.extra.get("versionsPluginVersion")}") @@ -31,11 +27,15 @@ buildscript { } } +plugins { + // https://github.com/jeremymailen/kotlinter-gradle/releases + id("org.jmailen.kotlinter") version "3.13.0" apply false +} + apply(from = "buildscripts/githooks.gradle") apply(from = "buildscripts/setup.gradle") subprojects { - apply(from = "../buildscripts/ktlint.gradle") apply(from = "../buildscripts/detekt.gradle") apply(from = "../buildscripts/versionsplugin.gradle") } diff --git a/buildscripts/ktlint.gradle b/buildscripts/ktlint.gradle deleted file mode 100644 index 8024b5e..0000000 --- a/buildscripts/ktlint.gradle +++ /dev/null @@ -1,14 +0,0 @@ -apply plugin: "org.jlleitschuh.gradle.ktlint" - -ktlint { - // https://github.com/pinterest/ktlint/releases - version = "0.45.1" - - reporters { - reporter "plain" - reporter "checkstyle" - reporter "html" - } - - outputColorName = "RED" -} \ No newline at end of file diff --git a/documentation/StaticAnalysis.md b/documentation/StaticAnalysis.md index 729c4d1..46beb66 100644 --- a/documentation/StaticAnalysis.md +++ b/documentation/StaticAnalysis.md @@ -16,14 +16,14 @@ To run a detekt validation, use the following Gradle command: [Ktlint](https://github.com/pinterest/ktlint) is a static analysis tool from Pinterest that prevents bike shedding when it comes to code formatting. It also comes with a Gradle task to automatically format your entire codebase, if it can. The benefit of a tool like this is to ensure everyone on the team will have code formatted the same way, and there's no debating around white spaces, indentation, imports, etc. -We use the [JLLeitschuh](https://github.com/jlleitschuh/ktlint-gradle) Ktlint Gradle plugin in this project. You can find the setup in [this Gradle file](/buildscripts/ktlint.gradle). +We use the [Kotlinter](https://github.com/jeremymailen/kotlinter-gradle) Ktlint Gradle plugin in this project. The following Gradle commands can be helpful: ``` // Will format the codebase -./gradlew ktlintFormat +./gradlew formatKotlin // Will check if everything is formatted correctly -./gradlew ktlintCheck +./gradlew lintKotlin ``` \ No newline at end of file diff --git a/git-hooks/pre-commit.sh b/git-hooks/pre-commit.sh index 753486b..093d89e 100644 --- a/git-hooks/pre-commit.sh +++ b/git-hooks/pre-commit.sh @@ -12,7 +12,7 @@ fi; echo "Running ktlint over these files:" echo "$CHANGED_FILES" -./gradlew --quiet ktlintFormat -PinternalKtlintGitFilter="$CHANGED_FILES" +./gradlew --quiet formatKotlin -PinternalKtlintGitFilter="$CHANGED_FILES" echo "Completed ktlint run." diff --git a/git-hooks/pre-push.sh b/git-hooks/pre-push.sh index a0cd68f..c43519f 100644 --- a/git-hooks/pre-push.sh +++ b/git-hooks/pre-push.sh @@ -2,5 +2,5 @@ echo "Running static analysis." -./gradlew ktlintCheck +./gradlew lintKotlin ./gradlew detekt \ No newline at end of file From 122dbaf809b21435c16776d54bd62ca0c0720621 Mon Sep 17 00:00:00 2001 From: Adam McNeilly Date: Tue, 31 Jan 2023 22:50:01 -0500 Subject: [PATCH 2/2] Fixing workflow. --- .github/workflows/android_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 8c9f88e..6d66971 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -20,4 +20,4 @@ jobs: run: ./gradlew test - name: Lint Checks - run: ./gradlew detekt ktlintCheck lint \ No newline at end of file + run: ./gradlew detekt lintKotlin lint \ No newline at end of file