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 ++-------------- 3 files changed, 17 insertions(+), 24 deletions(-) (limited to 'build-logic/src') 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") -- cgit v1.2.3