jdavisclark / JsFormat

Javascript formatting for Sublime Text 2 & 3
1.42k stars 222 forks source link

Add option to control keeping a newline at the end of the file. #158

Closed MaitreyaBuddha closed 6 years ago

MaitreyaBuddha commented 8 years ago

This is not the same as issue #11

The current default behavior (years later) is now to remove any newlines at the end of the file. It was the opposite when #11 was filed. This can be fixed with sublime option ensure_newline_at_eof_on_save (as mentioned), however that option now alters files on every save. The behavior I would like, and is likely most desired for editing files after creation, is to not alter the newline at the end of file at all. Just leave it be.

pleaseshutup commented 8 years ago

I would also prefer to have this left alone by jsFormat. ESLint standard rules like having a new line at the end of the file. jsFormat removes them. I don't want to force sublime to add a new line to all of my files on save because I do not always want that to happen.

friederbluemle commented 8 years ago

I think the current default behavior of JsFormat is broken: It removes the newline character at EOF. Every line in a text file should end with a newline character. Otherwise the last line would not be considered a line according to POSIX standard. Also see http://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline It would be nice to at least make it optional the remove this character. Otherwise it will result in files that don't work correctly with tools like cat, and cause Git warnings (\ No newline at end of file)

pleaseshutup commented 8 years ago

This can actually be solved by jsbeautifier

If you set "end_with_newline": true in your jsFormat settings for jsBeautifier then it will no longer remove (or will add) the trailing newline to the file.

jdavisclark commented 8 years ago

@pleaseshutup: bingo. This should be documented better.