This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +18
-25
lines changed
build-logic/src/main/kotlin/app/passwordstore/gradle Expand file tree Collapse file tree 4 files changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package app.passwordstore.gradle
2
2
3
3
import app.passwordstore.gradle.ktfmt.KtfmtCheckTask
4
4
import app.passwordstore.gradle.ktfmt.KtfmtFormatTask
5
+ import com.facebook.ktfmt.format.FormattingOptions
5
6
import java.util.concurrent.Callable
6
7
import org.gradle.api.Plugin
7
8
import org.gradle.api.Project
@@ -21,4 +22,16 @@ class KtfmtPlugin : Plugin<Project> {
21
22
projectDirectory.set(target.layout.projectDirectory)
22
23
}
23
24
}
25
+
26
+ companion object {
27
+ val DEFAULT_FORMATTING_OPTIONS =
28
+ FormattingOptions (
29
+ maxWidth = FormattingOptions .DEFAULT_MAX_WIDTH ,
30
+ blockIndent = 2 ,
31
+ continuationIndent = 2 ,
32
+ removeUnusedImports = true ,
33
+ debuggingPrintOpsAfterFormatting = false ,
34
+ manageTrailingCommas = true ,
35
+ )
36
+ }
24
37
}
Original file line number Diff line number Diff line change 1
1
package app.passwordstore.gradle.ktfmt
2
2
3
+ import app.passwordstore.gradle.KtfmtPlugin
3
4
import com.facebook.ktfmt.format.Formatter
4
- import com.facebook.ktfmt.format.FormattingOptions
5
5
import java.io.File
6
6
import kotlinx.coroutines.Dispatchers
7
7
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -50,15 +50,7 @@ abstract class KtfmtCheckTask : SourceTask() {
50
50
51
51
private fun checkFile (input : File ): Pair <Boolean , List <KtfmtDiffEntry >> {
52
52
val originCode = input.readText()
53
- val formattedCode =
54
- Formatter .format(
55
- FormattingOptions (
56
- style = FormattingOptions .Style .GOOGLE ,
57
- maxWidth = 100 ,
58
- continuationIndent = 2 ,
59
- ),
60
- originCode,
61
- )
53
+ val formattedCode = Formatter .format(KtfmtPlugin .DEFAULT_FORMATTING_OPTIONS , originCode)
62
54
val pathNormalizer = { file: File -> file.toRelativeString(projectDirectory.asFile.get()) }
63
55
return (originCode != formattedCode) to
64
56
KtfmtDiffer .computeDiff(input, formattedCode, pathNormalizer)
Original file line number Diff line number Diff line change 1
1
package app.passwordstore.gradle.ktfmt
2
2
3
+ import app.passwordstore.gradle.KtfmtPlugin
3
4
import com.facebook.ktfmt.format.Formatter
4
- import com.facebook.ktfmt.format.FormattingOptions
5
5
import java.io.File
6
6
import org.gradle.api.logging.LogLevel
7
7
import org.gradle.api.logging.Logger
@@ -24,19 +24,7 @@ abstract class KtfmtWorkerAction : WorkAction<KtfmtWorkerParameters> {
24
24
25
25
logger.log(LogLevel .DEBUG , " $name checking format: $relativePath " )
26
26
27
- val formattedText =
28
- Formatter .format(
29
- FormattingOptions (
30
- style = FormattingOptions .Style .GOOGLE ,
31
- maxWidth = FormattingOptions .DEFAULT_MAX_WIDTH ,
32
- blockIndent = 2 ,
33
- continuationIndent = 2 ,
34
- removeUnusedImports = true ,
35
- debuggingPrintOpsAfterFormatting = false ,
36
- manageTrailingCommas = true ,
37
- ),
38
- sourceText,
39
- )
27
+ val formattedText = Formatter .format(KtfmtPlugin .DEFAULT_FORMATTING_OPTIONS , sourceText)
40
28
41
29
if (! formattedText.contentEquals(sourceText)) {
42
30
logger.log(LogLevel .QUIET , " ${file.toRelativeString(projectDirectory)} : Format fixed" )
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ build-diffutils = "io.github.java-diff-utils:java-diff-utils:4.12"
39
39
build-download = " de.undercouch:gradle-download-task:5.6.0"
40
40
build-javapoet = " com.squareup:javapoet:1.13.0"
41
41
build-kotlin = { module = " org.jetbrains.kotlin:kotlin-gradle-plugin" , version.ref = " kotlin" }
42
- build-ktfmt = " com.facebook:ktfmt:0.50 "
42
+ build-ktfmt = " com.facebook:ktfmt:0.51 "
43
43
build-mavenpublish = " com.vanniktech:gradle-maven-publish-plugin:0.28.0"
44
44
build-metalava = " me.tylerbwong.gradle.metalava:plugin:0.3.5"
45
45
build-moshi = { module = " com.squareup.moshi:moshi" , version.ref = " moshi" }
You can’t perform that action at this time.
0 commit comments