Compare commits

..

2 Commits

Author SHA1 Message Date
Simon Rüegg 8367ac92b2 Only write changed files 2025-09-19 13:18:39 +02:00
Islon Scherer 618c6243c5 Fix bug in format apply (#1211) 2025-09-19 11:28:40 +02:00
8 changed files with 7 additions and 9 deletions
@@ -32,15 +32,17 @@ class CliFormatterApply(cliBaseOptions: CliBaseOptions, path: Path, private val
val contents = Files.readString(path)
val (formatted, stat) = format(path, contents)
status = if (status == 0) stat else status
if (stat != 0) continue
if (!silent && contents != formatted) {
if (stat != 0 || contents == formatted) continue
if (!silent) {
consoleWriter.write(path.toAbsolutePath().toString())
consoleWriter.appendLine()
consoleWriter.flush()
}
try {
path.writeText(formatted, Charsets.UTF_8)
} catch (e: IOException) {
consoleWriter.write("Could not overwrite `$path`: ${e.message}")
consoleWriter.appendLine()
consoleWriter.flush()
status = 1
}
@@ -32,6 +32,7 @@ class CliFormatterCheck(cliBaseOptions: CliBaseOptions, path: Path) :
status = if (status == 0) stat else status
if (contents != formatted) {
consoleWriter.write(path.toAbsolutePath().toString())
consoleWriter.appendLine()
consoleWriter.flush()
status = 1
}
@@ -39,6 +39,7 @@ constructor(
return Formatter().format(contents) to 0
} catch (pe: GenericParserError) {
consoleWriter.write("Could not format `$file`: $pe")
consoleWriter.appendLine()
consoleWriter.flush()
return "" to 1
}
@@ -66,6 +66,6 @@ class FormatterApplyCommand : BaseCommand(name = "apply", helpLink = helpLink) {
.flag()
override fun run() {
CliFormatterApply(baseOptions.baseOptions(emptyList()), path, silent)
CliFormatterApply(baseOptions.baseOptions(emptyList()), path, silent).run()
}
}
@@ -1,3 +0,0 @@
/// This file only contains a doc-comment
///
/// And nothing else
@@ -1,3 +0,0 @@
/// This file only contains a doc-comment
///
/// And nothing else