Js-beautify: { "brace_style": "preserve-inline" } not working as expected with multiline function parameters

Created on 24 Oct 2018  路  4Comments  路  Source: beautify-web/js-beautify


Hi, first a big thanks to you guys for such a great library !

I have a problem when I use multiline function arguments that contains objects:

// This is working OK for me and it is very readable

Expected Output

But when I try:

// This is working OK for me and it is very readable
    { myProp: true }, // I have just insterted this object

Actual Output

All is reformatted in one line...

myFunc('myString', { myProp: true }, andSoOn());

I am pretty sure it has to do with { "brace_style": "preserve-inline" } rule.


OS: Linux Mint
code Editor: VSCode



    "editor": {
        "formatOnSave": true
    "brace_style": "collapse,preserve-inline"

Thank you again ;)

javascript bug

All 4 comments

It is the collapse setting that is pulling the open-curly brace back to the previous line.

But it could be argued that preserve-inline should override that. The hard part is that beautifier can't tell if the block will be inline until it reaches the end of it. That is difficult in the current design.

Ok, I have tried with config:

    "brace_style": "none,preserve-inline"

And the result is the same...also I think this happen only in function params context, all others cases are ok, hope I have some time to check it out.

Hi, for those looking for a solution, here is a workaround:

myFunc( //
    { myProp: true }, //
    { myProp: true }, //
    { myProp: true });

When I put empty comment it wont reformat to one line. At least on VScode. It doesn't render less lisible and is easily removable projectwide with a search and replace (//\n)

Hope it can help...

Ouch. I'm glad you found a work around but that is a painful work around.
Just to be clear "none,preserve-inline" should work so I'm changing this to bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mubaidr picture mubaidr  路  6Comments

Hirse picture Hirse  路  3Comments

geakstr picture geakstr  路  3Comments

gabrielmaldi picture gabrielmaldi  路  3Comments

retan picture retan  路  3Comments