From 13752aba998b1f3c591d63a76e015df87e47b617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Kr=C3=B6ger?= Date: Wed, 14 May 2025 21:31:09 +0200 Subject: [PATCH] Fix extra newline from nimpretty when used with `--stdin` (#24951) Using `echo` to print file contents to stdout automatically adds a newline at the end of the file contents. When using nimpretty to auto format files on save in some editors which replace the file contents with the formatted ones this means that with every save/format operation an additional newline is added to the end of the file. Using `stdout.write` does not automatically add a newline at the end preventing this issue. Fixes #24950 (cherry picked from commit c1e6cf812f7f9d2a706d70d99cab8d0a89a7e791) --- nimpretty/nimpretty.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimpretty/nimpretty.nim b/nimpretty/nimpretty.nim index c860d2970e..ff193744f2 100644 --- a/nimpretty/nimpretty.nim +++ b/nimpretty/nimpretty.nim @@ -111,7 +111,7 @@ proc handleStdinInput(opt: PrettyOptions) = prettyPrint(path, path, opt) - echo(readAll(cfile)) + stdout.write(readAll(cfile)) close(cfile) removeFile(path)