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

Keep inline objects option #847

Closed
vccortez opened this issue Jan 20, 2016 · 1 comment
Closed

Keep inline objects option #847

vccortez opened this issue Jan 20, 2016 · 1 comment

Comments

@vccortez
Copy link

Hello, it would be great if we could have more control over plain object formatting.

Right now, any object, even the ones with only one parameter gets expanded. For example:

var object = { id: 10 };

Ends up transformed into:

var object = {
  id: 10
};

I personally don't think expanding every object is a good thing, not every object is going to be complex, specially plain javascript objects, so this formatting rule often becomes a minor annoyance that adds more lines to your source code.

Additionally (but maybe out of the scope of this feature request), this causes problems with a few javascript features of ES6 ( #511, #382 ), making the code seem ugly.

The internet is full of examples where plain objects are used inline, like this snippet from Node's about page:

http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World\n');
}).[...]

I think most of these issues could be solved if we had ways to tell jsbeautifier what to do about small plain objects ( maybe {name:'hello'} -> { name: 'hello' }) instead of using the same behavior of function blocks.

@bitwiseman
Copy link
Member

You are not alone in wanting this. See #315
I just updated that issue's title to include the word "inline".
But thank you for taking the time to submit a full and well-reasoned feature request. 😄

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

2 participants