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

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

Open
top-kat opened this issue Oct 24, 2018 · 4 comments

Comments

@top-kat
Copy link

top-kat commented Oct 24, 2018

Description

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
myFunc('myString',
    myFunc2(),
    andSoOn());

Expected Output

But when I try:

// This is working OK for me and it is very readable
myFunc('myString',
    { myProp: true }, // I have just insterted this object
    andSoOn());

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.

Environment

OS: Linux Mint
code Editor: VSCode

Settings

Example:

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

Thank you again ;)

@bitwiseman
Copy link
Member

bitwiseman commented Oct 24, 2018

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.

@top-kat
Copy link
Author

top-kat commented Oct 26, 2018

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.

@top-kat
Copy link
Author

top-kat commented Nov 13, 2018

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...

@bitwiseman bitwiseman added this to the v1.8.x milestone Nov 13, 2018
@bitwiseman
Copy link
Member

@sebRomeo
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.

@bitwiseman bitwiseman modified the milestones: v1.9.x, v1.10.x Apr 29, 2019
@bitwiseman bitwiseman modified the milestones: v1.10.x, v1.10.xx Jan 14, 2020
@bitwiseman bitwiseman modified the milestones: v1.10.x, v1.11.x Apr 5, 2020
@bitwiseman bitwiseman modified the milestones: v1.11.x, v1.12.x Aug 13, 2020
@bitwiseman bitwiseman modified the milestones: v1.12.x, 1.13.x Aug 20, 2020
@bitwiseman bitwiseman modified the milestones: v1.13.1, v1.13.x Jan 8, 2021
@bitwiseman bitwiseman modified the milestones: v1.13.6, v1.13.x Jan 26, 2021
@bitwiseman bitwiseman modified the milestones: v1.13.7, v1.13.x Apr 13, 2021
@bitwiseman bitwiseman modified the milestones: v1.14.1, v1.14.x, v1.15.x Mar 28, 2022
@bitwiseman bitwiseman removed this from the v1.14.3 milestone Apr 9, 2022
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