Auto-reformatting strips the trailing newline
Closed this issue · 6 comments
When I save a dhall file and it gets reformatted, the trailing newline gets deleted, so I end up with git-diff
saying
...
+}
\ No newline at end of file
FWIW when I run dhall format --inplace FILE
for the same file, it restores the newline.
Ah, interesting! This is because the default in my reformatter.el
library (which is used for dhall-format
is to run whitespace-cleanup
after running the formatter. That choice was actually largely a result of dhall-format
failing to strip trailing whitespace in general. Changing this stripping behaviour would result in a messier file, and I don't personally think the git-diff
message about is really a problem.
Note that that linked issue is still open, but I haven't tested whether the latest dhall format
displays the same behaviour.
I acknowledge that while the git-diff
message is annoying, it is a 1-time cost to pay (it really only shows up for dhall files that have been first hand-curated in an external editor or have been run with dhall format
first independent of dhall-mode
).
One thing that surprised me though is that dhall-mode
's reformatter overrides the (setq require-final-newline t)
I have in my Emacs config.
Ah, interesting! This is because the default in my
reformatter.el
library (which is used fordhall-format
is to runwhitespace-cleanup
after running the formatter. That choice was actually largely a result ofdhall-format
failing to strip trailing whitespace in general. Changing this stripping behaviour would result in a messier file, and I don't personally think thegit-diff
message about is really a problem.
I see. How about just appending a newline if the last character is not a newline? It would match the raw dhall format
behavior as well as (coincidentally) respect setting (setq require-final-newline t)
.
FWIW I cannot reproduce this any more, with dhall 1.24.0
. This is strange because I have not changed my dhall-mode installation. It is doubly strange because both the old dhall 1.19.0 version I was using and also the current one 1.24.0 have the same "do not strip the trailing newline" behavior.
Feel free to close.
Ah, thanks for following up! I think the whitespace handling in Dhall format might have been fixed, since there's activity on that linked issue. I'll go ahead and close this now.