From b596930ec5544148308401c57bbb2b412234c3f5 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 14 Jun 2024 20:34:09 +0530 Subject: fix(deps): update ktfmt to 0.51 --- .../main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt | 13 +++++++++++++ .../app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt | 12 ++---------- .../app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt | 16 ++-------------- gradle/libs.versions.toml | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt index 90636e4b..7aac48b5 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt @@ -2,6 +2,7 @@ package app.passwordstore.gradle import app.passwordstore.gradle.ktfmt.KtfmtCheckTask import app.passwordstore.gradle.ktfmt.KtfmtFormatTask +import com.facebook.ktfmt.format.FormattingOptions import java.util.concurrent.Callable import org.gradle.api.Plugin import org.gradle.api.Project @@ -21,4 +22,16 @@ class KtfmtPlugin : Plugin { projectDirectory.set(target.layout.projectDirectory) } } + + companion object { + val DEFAULT_FORMATTING_OPTIONS = + FormattingOptions( + maxWidth = FormattingOptions.DEFAULT_MAX_WIDTH, + blockIndent = 2, + continuationIndent = 2, + removeUnusedImports = true, + debuggingPrintOpsAfterFormatting = false, + manageTrailingCommas = true, + ) + } } diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt index c29dbd2f..58ef432f 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt @@ -1,7 +1,7 @@ package app.passwordstore.gradle.ktfmt +import app.passwordstore.gradle.KtfmtPlugin import com.facebook.ktfmt.format.Formatter -import com.facebook.ktfmt.format.FormattingOptions import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -50,15 +50,7 @@ abstract class KtfmtCheckTask : SourceTask() { private fun checkFile(input: File): Pair> { val originCode = input.readText() - val formattedCode = - Formatter.format( - FormattingOptions( - style = FormattingOptions.Style.GOOGLE, - maxWidth = 100, - continuationIndent = 2, - ), - originCode, - ) + val formattedCode = Formatter.format(KtfmtPlugin.DEFAULT_FORMATTING_OPTIONS, originCode) val pathNormalizer = { file: File -> file.toRelativeString(projectDirectory.asFile.get()) } return (originCode != formattedCode) to KtfmtDiffer.computeDiff(input, formattedCode, pathNormalizer) diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt index ef7e63e7..c955adbe 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt @@ -1,7 +1,7 @@ package app.passwordstore.gradle.ktfmt +import app.passwordstore.gradle.KtfmtPlugin import com.facebook.ktfmt.format.Formatter -import com.facebook.ktfmt.format.FormattingOptions import java.io.File import org.gradle.api.logging.LogLevel import org.gradle.api.logging.Logger @@ -24,19 +24,7 @@ abstract class KtfmtWorkerAction : WorkAction { logger.log(LogLevel.DEBUG, "$name checking format: $relativePath") - val formattedText = - Formatter.format( - FormattingOptions( - style = FormattingOptions.Style.GOOGLE, - maxWidth = FormattingOptions.DEFAULT_MAX_WIDTH, - blockIndent = 2, - continuationIndent = 2, - removeUnusedImports = true, - debuggingPrintOpsAfterFormatting = false, - manageTrailingCommas = true, - ), - sourceText, - ) + val formattedText = Formatter.format(KtfmtPlugin.DEFAULT_FORMATTING_OPTIONS, sourceText) if (!formattedText.contentEquals(sourceText)) { logger.log(LogLevel.QUIET, "${file.toRelativeString(projectDirectory)}: Format fixed") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 118933a0..bdb771e7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,7 +39,7 @@ build-diffutils = "io.github.java-diff-utils:java-diff-utils:4.12" build-download = "de.undercouch:gradle-download-task:5.6.0" build-javapoet = "com.squareup:javapoet:1.13.0" build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -build-ktfmt = "com.facebook:ktfmt:0.50" +build-ktfmt = "com.facebook:ktfmt:0.51" build-mavenpublish = "com.vanniktech:gradle-maven-publish-plugin:0.28.0" build-metalava = "me.tylerbwong.gradle.metalava:plugin:0.3.5" build-moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" } -- cgit v1.2.3