Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atom-beautify does not support js-beautify eol auto setting #829

Closed
garretwilson opened this issue Feb 25, 2016 · 5 comments
Closed

atom-beautify does not support js-beautify eol auto setting #829

garretwilson opened this issue Feb 25, 2016 · 5 comments

Comments

@garretwilson
Copy link
Contributor

Description

js-beautify in its latest version supports the value "auto" for the eol setting. In auto-eol mode, js-beautify purports to auto-detect the line ending style (e.g. LF or CRLF) and maintain that style. (I have not verified this new functionality, but @bitwiseman assures me that it is working in the latest release:

beautifier/js-beautify#829

However I cannot get it to work in atom-beautify. @Glavin001 assures me that atom-beautify is using the latest js-beautify, and that my problem probably stems from an outdated js-beautify, and that I should simply reinstall atom-beautify.

So I uninstalled and re-installed atom-beautify. I'm running a fresh version 0.28.22. Still no luck.

Steps to Reproduce

I started with the following .jsbeautifyrc file:

{
    "eol": "\r\n",
    "indent_with_tabs": true,
    "preserve_newlines": true,
    "max_preserve_newlines": 2,
    "end_with_newline": true,
    "wrap_line_length": 0,
    "unformatted": [
        "a", "abbr", /*"area",*/ "audio", "b", "bdi", "bdo", "br", "button", "canvas", "cite", "code", "data", "datalist", "del", "dfn", "em", "embed", "i", "iframe", "img", "input", "ins", "kbd", "keygen", "label", "map", "mark", "math", "meter", "noscript", "object", "output", "progress", "q", "ruby", "s", "samp", "script", "select", "small", "span", "strong", "sub", "sup", "svg", "template", "textarea", "time", "u", "var", "video", "wbr",
        "address", "dt", "h1", "h2", "h3", "h4", "h5", "h6", "pre",
        "acronym", "big", "font", "small", "strike", "tt"
    ]
}

Pressing Ctrl+Alt+B formatted that using CRLF as a line ending, just as I had requested. So, just to be sure that atom-beautify was picking up the correct .jsbeautifyrc file, I changed eol to "\n":

{
    "eol": "\n",
    "indent_with_tabs": true,
    /*abridged for saving space in bug report*/
}

Sure enough, now atom-beautify uses LF instead of CRLF when formatting my file---so I know I'm working with the correct .jsbeautifyrc file.

So I remove the eol setting altogether; if I understand @bitwiseman and @Glavin001 , atom-beautify should pass everything to js-beautify, and js-beautify should detect the line endings.

But no go. I get LF line endings, just like atom-beautify+js-beautify used to do. Apparently nothing has changed.

Trying to further investigate this, I changed the eol setting to "auto". Surely this can't go wrong!

{
    "eol": "auto",
    "indent_with_tabs": true,
    /*abridged for saving space in bug report*/
}

You know what happens? It uses the literal string "auto" for my line endings! Yes, that produces a single line with "auto" interspersed throughout!!

@Glavin001
Copy link
Owner

Sounds like Atom Beautify is working exactly as expected, passing options to js-beautify. The more I read, the more it is clear to me that this is a js-beautify bug, regarding how js-beautify is handling the option eol.

Have you tried what was recommended at beautifier/js-beautify#829 (comment) ?

If you believe this isn't working on the js-beautify side, you can test it by saving your file and then running the js-beautify command on the file.

Also for this and future issues please provide the debugging information in a Gist as instructed by https://github.com/Glavin001/atom-beautify/blob/master/ISSUE_TEMPLATE.md#how-to-create-debugmd-gist
Without it I am unable to efficiently assist with debugging, and therefore I will not be doing so until the debugging Gist is added. Thanks!

@Glavin001
Copy link
Owner

What can be done is adding official support in Atom Beautify for:

  • add option for manually selecting the EOL
    • to languages
      • HTML
      • JavaScript
      • CSS
    • to beautifier
  • automatically detect the EOL setting from the Atom editor
    • use as default value for eol option

However, this is all above and beyond the fact that:

  • all options are passed directly to js-beautify for JavaScript and for HTML and others, excluding CSS
  • Atom Beautify does not perform any beautification, so changing the eol setting within .jsbeautifyrc will only change how js-beautify beautifies your code. Using auto and having it show up as the literal string auto is all logic implemented within js-beautify and only confirms that Atom Beautify is working correctly by passing auto to js-beautify.

I recommend the following actions:

After the above have been completed, I can then continue investigating Atom Beautify internally for why this issue may be occurring. Thanks.

@prettydiff
Copy link
Collaborator

@Glavin001 Yes, for Pretty Diff eol support use the option crlf

http://prettydiff.com/documentation.xhtml#crlf

The value true will use \r\n as the line termination sequence, which should be as similar as CRLF as can be expected from JavaScript. The default value false will use \n which should equate to LF.

@garretwilson
Copy link
Contributor Author

The more I read, the more it is clear to me that this is a js-beautify bug, regarding how js-beautify is handling the option eol.

Yes, it does seem like that, and I'm sorry to have bothered you with it. I only brought it up here because I was assured on the other side that there was no problem in js-beautify and it absolutely had to be an atom-beautify problem.

I hope I can help you with other areas of atom-beautify in the future.

@bitwiseman
Copy link
Contributor

@garretwilson - 23 days ago I said:

If you believe this isn't working on the js-beautify side, you can test it by saving your file and then running the js-beautify command on the file.

And instead of doing that, you filed this issue with atom-beautify. If you'd simply done as I'd asked at the time, you would have saved yourself and others a lot of time and frustration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants