This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed
build-logic/src/main/kotlin/app/passwordstore/gradle/ktfmt Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import kotlinx.coroutines.async
9
9
import kotlinx.coroutines.awaitAll
10
10
import kotlinx.coroutines.coroutineScope
11
11
import kotlinx.coroutines.runBlocking
12
+ import org.gradle.api.GradleException
12
13
import org.gradle.api.file.DirectoryProperty
13
14
import org.gradle.api.file.FileCollection
14
15
import org.gradle.api.tasks.IgnoreEmptyDirectories
@@ -36,10 +37,12 @@ abstract class KtfmtCheckTask : SourceTask() {
36
37
coroutineScope {
37
38
val results = inputFiles.map { async { checkFile(it) } }.awaitAll()
38
39
if (results.any { (notFormatted, _) -> notFormatted }) {
39
- results
40
- .map { (_, diffs) -> diffs }
41
- .forEach { diffs -> KtfmtDiffer .printDiff(diffs, logger) }
42
- error(" [ktfmt] Found unformatted files" )
40
+ val prettyDiff =
41
+ results
42
+ .map { (_, diffs) -> diffs }
43
+ .flatten()
44
+ .joinToString(separator = " \n " ) { diff -> diff.toString() }
45
+ throw GradleException (" [ktfmt] Found unformatted files\n ${prettyDiff} " )
43
46
}
44
47
}
45
48
}
Original file line number Diff line number Diff line change 1
1
package app.passwordstore.gradle.ktfmt
2
2
3
- data class KtfmtDiffEntry (val input : String , val lineNumber : Int , val message : String )
3
+ data class KtfmtDiffEntry (val input : String , val lineNumber : Int , val message : String ) {
4
+
5
+ override fun toString (): String {
6
+ return " $input :$lineNumber - $message "
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import com.github.difflib.patch.ChangeDelta
5
5
import com.github.difflib.patch.DeleteDelta
6
6
import com.github.difflib.patch.InsertDelta
7
7
import java.io.File
8
- import org.gradle.api.logging.Logger
9
8
10
9
object KtfmtDiffer {
11
10
fun computeDiff (
@@ -26,10 +25,4 @@ object KtfmtDiffer {
26
25
KtfmtDiffEntry (pathNormalizer(inputFile), line, message)
27
26
}
28
27
}
29
-
30
- fun printDiff (entries : List <KtfmtDiffEntry >, logger : Logger ) {
31
- entries.forEach { entry ->
32
- logger.error(" ${entry.input} :${entry.lineNumber} - ${entry.message} " )
33
- }
34
- }
35
28
}
You can’t perform that action at this time.
0 commit comments