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

Option to preserve inline object #776

Closed
Zephyrrus opened this issue Feb 1, 2016 · 13 comments
Closed

Option to preserve inline object #776

Zephyrrus opened this issue Feb 1, 2016 · 13 comments

Comments

@Zephyrrus
Copy link

Not sure why it's happening now and never happened before to me, but the JS beautifier expands every object to a key:value per line, instead of keeping them in a single line. This is very annoying for short objects which could be kept on a single line but instead are expanded to several lines.

@prettydiff
Copy link
Collaborator

The default beautifier for JavaScript is JS Beautify unless you change the beautifier in the Atom Beautify settings to Pretty Diff. JS Beautify had a big update last week featuring more advanced object support and destructuring.

Would you be able to provide a sample of code so that we can produce the issue and indicate if you are using the default beautifier or Pretty Diff?

@Zephyrrus
Copy link
Author

I am using the default JS Beautify, and a simple example is

      "databaseStructure": [
        {name: "id", type: "autonumber", primaryKey: true},
        {name: "uid", type: "number", required: true},
        {name: "reason", type: "string"},
        {name: "addedDate", type: "datetime", required: true},
        {name: "addedBy", type: "number", required: true}
      ]

which get's expanded to

"databaseStructure": [
          {
              name: "id",
              type: "autonumber",
              primaryKey: true
          },
          {
              name: "uid",
              type: "number",
              required: true
          },
          {
              name: "reason",
              type: "string"
          },
          {
              name: "addedDate",
              type: "datetime",
              required: true
          },
          {
              name: "addedBy",
              type: "number",
              required: true
          }
      ]

after using JS beautify, and it's very annoying for me because I prefer to keep them on a single line.

@prettydiff
Copy link
Collaborator

The output appears to be completely correct, though you are asking for a different stylistic preference. I will include @bitwiseman so that he can weigh in if this is an enhancement that he would like to pursue for JS Beautify.

I just checked this in Pretty Diff and I am not supporting this preference either. We both support object flattening, but only in certain contexts. Universal object flattening is not something that has been requested to me and is generally not desired if the objects large enough to produce horizontal scrolling.

@bitwiseman
Copy link
Contributor

JSBeautify 1.6.x supports keeping inline objects by setting brace-style to colapse-preserve-inline.

This input remains unchanged when that setting is used:

{
    "databaseStructure": [
        { name: "id", type: "autonumber", primaryKey: true },
        { name: "uid", type: "number", required: true },
        { name: "reason", type: "string" },
        { name: "addedDate", type: "datetime", required: true },
        { name: "addedBy", type: "number", required: true }
    ]
}

@prettydiff
Copy link
Collaborator

Then a new option will need to be added to the tool to support this feature.

@bitwiseman
Copy link
Contributor

Ah, I see. I could make this functionality the default for collapse or I could add a separate setting, but doesn't seem to make a lot of sense to have expand with preserve-inline.

@kaaloo
Copy link
Contributor

kaaloo commented Feb 3, 2016

I'd love to have support for "brace_style": "collapse-preserve-inline" too!

@prettydiff
Copy link
Collaborator

@kaaloo Would you mind writing a pull request add this option to the tool? It would be really helpful to the project and just think of all that open source fame and glory you would receive as a project contributor.

@kaaloo
Copy link
Contributor

kaaloo commented Feb 3, 2016

Ha ha, sure I can try!

@kaaloo
Copy link
Contributor

kaaloo commented Feb 3, 2016

There you go, seems to work on my end.

#779

Glavin001 added a commit that referenced this issue Feb 20, 2016
[#776] Bump jsbeautify to 1.6.2.  Add support for collapse-preserve-inline
@noah-wisch
Copy link

Is there a new way to do this now because I cannot for the life of me figure out how to preserve my inline objects at the moment... Thanks!

@stale
Copy link

stale bot commented Nov 4, 2017

This issue has been automatically marked as stale because it has not had recent activity. If this is still an issue, please add a comment. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 4, 2017
@stale stale bot closed this as completed Nov 11, 2017
@Shakes03
Copy link

@noah-wisch hit the Debug option under the Atom Beautify menu... and see which language setting to change. I was changing my Java Script brace-style but Atom Beautify was applying JSX beautify settings to my .js files.

```jsx
'use strict';
const {

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