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

Keeping New lines #96

Closed
wisec opened this issue Feb 14, 2012 · 13 comments
Closed

Keeping New lines #96

wisec opened this issue Feb 14, 2012 · 13 comments

Comments

@wisec
Copy link

wisec commented Feb 14, 2012

Would it be possible to keep original newlines by simply adding:
preserve_max_newlines:1
to beautify options?

By modifying n_newlines condition it's "probably" easy to preserve the nl.
What do you think?

--- beautify.js 2012-02-14 15:37:23.000000000 +0100
+++ beautify.js 2012-02-14 15:55:37.000000000 +0100
@@ -345,7 +345,7 @@ function js_beautify(js_source_text, opt
             }

             if (opt_preserve_newlines) {
-                if (n_newlines > 1) {
+                if (n_newlines > 0) {
                     for (i = 0; i < n_newlines; i += 1) {
                         print_newline(i === 0);
                         just_added_newline = true;

Of course if the patch is wrong i'd like to understand why.

Thanks

@einars
Copy link
Contributor

einars commented Feb 14, 2012

Hmm, what would be achieved by keeping the newlines? This would effectively forbid the beautifier to make any meaningful changes, as e.g

var a =
1;

would not be restored to any beautiful form. The preserve_newlines options were implemented to keep the blank lines between the blocks of code intact, but I don't see the use in preserving all existing nl's, but please correct me if i'm wrong, maybe I misunderstood something.

@wisec
Copy link
Author

wisec commented Feb 14, 2012

broadly speaking I'd agree, but if you consider unfixed issues like:
b++
c=++o

which become:
b++c=++o

or similar, I'd say this feature is worth exposing..unless it breaks something else of course :)

That way you wouldn't break original newlines (and original js) but you would still beautify it.

Looking forward to your reply

@wisec
Copy link
Author

wisec commented Feb 14, 2012

I mean, newlines are definitely metachars as well, so unless there's the chance to be perfect in js sintax, I'd prefer to have the option to be conservative on newlines.
I'm not saying to be always like that, just to have an option to be like that :)

@nightwing
Copy link
Contributor

+1 on this

usually while typing i have newlines the way i want but some spaces are missing
it would be nice if editor could do this

var a=1
if(a==1)
 b+=x

var a = 1
if (a == 1)
    b += x

@einars
Copy link
Contributor

einars commented Feb 14, 2012

Yes, now I see the point in that.

@chtenb
Copy link

chtenb commented Dec 1, 2012

Is this already implemented in the python version? It would be cool if

if(true)
 bar();

wouldnt be converted to

if(true) bar();

Some of my colleagues dislike it when I use jsbeautifier, for the above reason. :(

@ghost
Copy link

ghost commented Mar 7, 2013

@wisec
Copy link
Author

wisec commented Mar 7, 2013

@hickop +1 :)

@bitwiseman
Copy link
Member

This is at least partially addressed by my recent changes to newline preservation.

But I see where you're headed with this - having an option where there would still be some formatting but newlines always kept.

@bitwiseman
Copy link
Member

I'm going to close this. If the new behavior is insufficient, please reopen.

@jonschlinkert
Copy link
Contributor

I know this issue was created with js in mind, but it would be great to have a fix for HTML as well.

@jonschlinkert
Copy link
Contributor

@bitwiseman
Copy link
Member

Please file a new issue.

@bitwiseman bitwiseman reopened this Jun 5, 2013
Kingwl pushed a commit to Kingwl/js-beautify that referenced this issue Sep 18, 2017
Kingwl pushed a commit to Kingwl/js-beautify that referenced this issue Sep 18, 2017
fix issue beautifier#96



See merge request !36
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

6 participants