summaryrefslogtreecommitdiff
path: root/build-logic/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'build-logic/src/main')
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt13
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt12
-rw-r--r--build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtWorkerAction.kt16
3 files changed, 17 insertions, 24 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<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,
+ )
+ }
}
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<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)
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<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")