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

Format json in line #114

Closed
freewind opened this issue May 22, 2012 · 3 comments
Closed

Format json in line #114

freewind opened this issue May 22, 2012 · 3 comments

Comments

@freewind
Copy link

At present, jsbeautify will format json into multi-lines. For example:

var items = nativeUsers.find({ email: '[email protected]' }, _).toArray(_);

will be formatted as:

var items = nativeUsers.find({
    email: '[email protected]'
}, _).toArray(_);

But I think it's kept inline will be better for this code.

Will jsbeautify handle it like this:

  1. if { is at the line end, it will be formatted into multi-lines:

    var items = nativeUsers.find({
                       email: '[email protected]' }, _).toArray(_);
    
  2. if not, format them inline

So, we can control if the json be formatted inline or multiline

@einars
Copy link
Contributor

einars commented May 22, 2012

  1. if { is at the line end, it will be formatted into multi-lines:
  2. if not, format them inline

That's a good idea, but, sadly, this wouldn't work good at all. The
beautifier is used extremely often to unpack packed/compressed/minified
scripts, and this would mean that for packed scripts/jsons/etc, even
the large objects are always formatted inline.

The proper solution, I guess, would be seeing physically how many items
are there inside the object, and deciding the formatting on that, but I
don't see how to do that nicely in the current implementation :(

Einar.

@freewind
Copy link
Author

At least we can provide such a configuration, and by default it's disabled, so it won't change the behavior of current.

But if I enable it, it will work as I described above.

I think it's very useful when I use jsbeautifier as my javascript formatter when coding -- which I have fully control of my code.

@bitwiseman
Copy link
Member

I agree there are scenarios where this would be nice, but to handle them right (even in a configuration only case) would require significant work - see #200 for related discussion. If you can find a way to do it and add the tests, submit a pull request and we can discuss.

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

3 participants