web-beautify icon indicating copy to clipboard operation
web-beautify copied to clipboard

Please preserve the trailing newline

Open andersk opened this issue 7 years ago • 2 comments

If you web-beautify-js the entire buffer, the trailing newline gets deleted (which defies UNIX conventions and annoys Git users, among other things).

If you web-beautify-js a region that includes a trailing newline, that newline gets deleted, even if that smashes the last line in the region into the first line following the region, which may even change the meaning of code that was relying on automatic semicolon insertion.

Please pass the -n/--end_with_newline option to js-beautify (beautify-web/js-beautify#492), or otherwise preserve the trailing newline. (Perhaps you want to avoid adding a newline inside a region that ends in the middle of a line, but that’s probably a rare case.)

andersk avatar Jun 26 '17 22:06 andersk

I'm having a problem with this as well. The before-save-hook instructions in README.md seem to conflict with require-final-newline, as the web-beautify-js-buffer call seems to happen after Emacs has added the final newline character.

jonkri avatar Nov 18 '18 18:11 jonkri

Here is a .jsbeautifyrc configuration example that could serve as an alternative to the -n option:

{
    "end_with_newline": true,
    "html": {
        "css": {
            "end_with_newline": false        
        },
        "js": {
            "end_with_newline": false        
        }
    }
}

The inner end_with_newline fields disables empty lines before </script> and </style>.

jonkri avatar Dec 08 '18 17:12 jonkri