editorconfig-emacs icon indicating copy to clipboard operation
editorconfig-emacs copied to clipboard

Remove final newlines when insert_final_newline = false

Open vermiculus opened this issue 1 year ago • 4 comments

https://github.com/editorconfig/editorconfig-emacs/blob/648f0cf9aeb72db77b252832a58367332b7bc055/editorconfig.el#L592-L606

Creating a tracking issue for the known FIXME.

vermiculus avatar Oct 20 '24 01:10 vermiculus

I'm thinking a local before-save hook could address this? ~~It'd be a little hacky, but it may work.~~ Looks like that's exactly what editorconfig-set-trailing-ws does. I'll prep a patch.

vermiculus avatar Oct 20 '24 01:10 vermiculus

Creating a tracking issue for the known FIXME.

I'm not sure it's really what we want.

To me, "require_final_newline = false" means literally that a final newline is merely "not required". It doesn't mean it's harmful.

require_final_newline is important because plain-text files whose last line does not end with LF have been known to be mis-handled by many tools. In contrast AFAIK removing an "unnecessary final newline" has never been necessary, it' merely a question of convention of preference.

"require_final_newline = false" can also be used for files where every byte counts, i.e. where the presence or absence of a terminating newline needs to be reserved.

monnier avatar Oct 20 '24 02:10 monnier

It's not really up to us to determine what this key should do. From the site:

insert_final_newline: set to true to ensure file ends with a newline when saving and false to ensure it doesn't.

It's in the spec.


To be clear, I'm working on getting this project to switch their style for all the reasons you cite, but we should adhere to the spec regardless.

vermiculus avatar Oct 20 '24 04:10 vermiculus

To be clear, I'm working on getting this project to switch their style for all the reasons you cite, but we should adhere to the spec regardless.

I'm known to disagree already on other parts of the spec, and to disagree with "adhere to the spec regardless". 🙂

monnier avatar Oct 20 '24 16:10 monnier

We can leave the last line as it is by setting "require_final_newline = unset" (or simply removing this property from .editorconfig).

I agree that it's natural to think that setting "require_final_newline = false" doesn't explicitly remove the final newline, but editorconfig spec defines actually it does. And changing this would require discussion with editorconfig plugin maintainers of other editors...

10sr avatar Oct 25 '24 12:10 10sr