yasuyk / web-beautify

Format HTML, CSS and JavaScript/JSON by js-beautify
GNU General Public License v3.0
219 stars 21 forks source link

Please preserve the trailing newline #30

Open andersk opened 7 years ago

andersk commented 7 years ago

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.)

jonkri commented 5 years ago

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 commented 5 years ago

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>.