-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 or inline "short objects" on a single line #315
Comments
+1 ... at least one propert object could stay on single line so
|
+1 |
Popular request. 😄 The old pull request of for this was done before we had line wrapping. Having the line wrap should make it easier. We do detect when we are inside an object declaration, so that's not bad, but we detect it late (see #200), so it may involve some back tracking to fix up an expanded object. |
I am all for this but I have a question. What if an object literal has exactly one property which in itself is an object literal with exactly one property? This could be repeated several times. In the example I have below I would actually prefer the code to be formatted on one line. Others may disagree but I think it is an important aspect to consider in this. This could be taken to extremes where the code must be wrapped due to line length but I do have cases in my code where:
|
@TheLudd I totally agree and was going to suggest this myself. Possibly a depth option as well. There is a limit to how readable that is after some levels deep. I would say what you have there would be the max default. |
@mokkabonna Good idea about the depth option. That eliminates some ambiguity of how code like this should be formatted. If it is doable... |
If not depth, maybe limit it by length... say it wraps after 80 chars. Not as elegant as depth but whatever can be doable quickly. |
+1 I prefer the idea of length. If it can all fit in the width of the window, let it. |
Strong support for this. Added to v1.5.0. |
👏👏👏👏 |
Is it also gonna preserve single line statements like this? if(someCondition) { return something; } |
That is as spec/implementation decision. It seems possible, but might not be a good idea to join them together. |
Agreed. Not sure how you want to track it though, maybe another issue "Preserve short expressions/statements on single line"? |
Sure, and note that it is related to this issue. |
Done. #338 |
FYI, This is basically another version #114 . One of the oldest open issues. |
Any updates on this? js-beautify is one of the best formatters out there except for this remaining issue. |
I think this is the single reason I'm not running js beautifier on save. |
+1 |
As much as I want to do this in 1.5.0, I'm going to have to punt it to 1.5.2. There are a a large number of changes already in 1.5.0, and this is a significant feature that is going to take some iterating and feedback to land cleanly. It is certainly the highest priority enhancement for 1.5.2. |
👍 I see |
Updated my comment above. |
Ok thanks. Will look for it in the next release then. |
👍 |
1 similar comment
+1 |
+1 hope this is done soon |
@nerdpad - it is done. |
Can we use it with Brackets? o_O |
@C-Weinstein - Perhaps you could open a new issue with example of input and desired output? |
For people like me coming here looking for a way to make it work: it works and can be enabled with the options in .jsbeautifyrc
|
Unfortunately, that didn't work :( But thanks for trying. |
@Ceyaje - How didn't work? Where didn't it work? What were your inputs and outputs? |
Input was
It "beautifies" to
|
@Ceyaje you need set option "brace-style" to "collapse-preserve-inline" |
@kutsan - Please open a new issue. |
I could not find expand-preserve-inline option with html file in atom. I write javascript in both html file and js file. |
Place "preserve-inline" after the setting you want to use (collapse, expand, etc.) "brace_style": "collapse,preserve-inline" |
https://i.gyazo.com/2831254cc47d08c879c7d36a7f1a30d0.png The above happens, however my brace style is collapse-preserve-inline. I read the full thread, I don't believe I'm doing anything incorrectly. Already restarted Atom, just in case, nothing. |
Any update on this? collapse-preserve-inline still expands the arrow function onto multiple lines. |
@grandslammer - Please take a look at open issues that include the word "arrow". If you don't see an issue that covers what you're talking about, please open a new issue. |
I'm sorry: Original topic is "Option to preserve or inline "short objects" on a single line #315? |
@ainthek it's |
How about the settings in vs code latest version to fix this issue? |
In vs code 1.20.1 , i cannot get the style "brace_style": "expand,preserve-inline", to work. Input : const { dialog } = require("electron").remote; Output (After selecting this area and clicking F1 ---> Beautify Selection) : NO CHANGE :( Expected Output : P.S ----> the distorted input was obtained after Beautifying the whole file. Nobody writes code in that distorted way :P |
For vscode, adding below in user settings worked for me: Thank you for the support guys. |
@sulkhanp - Please file an issue describing the behavior. |
@vipingoel 's solution works! |
"brace_style": "expand,preserve-inline" doesn't work. expect behavior:
current behavior:
|
@SiJinmin these are not short objects and therefore not related to this issue. |
@vipingoel It works. I'm really happy. Thanks!!! |
Typically the JS Beautifier expands all JS object declarations into multiple lines, each line having a key value pair. However, this is overly verbose for many situations (e.g. short objects which could easily fit on a single line).
Additional details found here: #55
The text was updated successfully, but these errors were encountered: