Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix(deps): update ktfmt to 0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
msfjarvis committed Jun 14, 2024
1 parent 4c0b6d1 commit b596930
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +22,16 @@ class KtfmtPlugin : Plugin<Project> {
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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -50,15 +50,7 @@ abstract class KtfmtCheckTask : SourceTask() {

private fun checkFile(input: File): Pair<Boolean, List<KtfmtDiffEntry>> {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,19 +24,7 @@ abstract class KtfmtWorkerAction : WorkAction<KtfmtWorkerParameters> {

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")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit b596930

Please sign in to comment.