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

Formatting breaks object operator -> #150

Open
sven-ahrens opened this issue Mar 3, 2022 · 7 comments
Open

Formatting breaks object operator -> #150

sven-ahrens opened this issue Mar 3, 2022 · 7 comments

Comments

@sven-ahrens
Copy link

sven-ahrens commented Mar 3, 2022

Description

In my blade file I've multiple @checked directives that include a php variable accessing a method.

        <div>
            <label>
                <input
                    type="checkbox"
                    value="1"
                    name="myCheckbox"
                    @checked(collect($checkbox->getValues()->get('myCheckbox'))->contains('1'))
                {{ __('myCheckbox.title') }}
            </label>
        </div>

When I format this, it turns into:

        <div>
            <label>
                <input
                    type="checkbox"
                    value="1"
                    name="myCheckbox"
                    @checked(collect($checkbox-
                >getValues()->get('myCheckbox'))->contains('1'))
                {{ __('myCheckbox.title') }}
            </label>
        </div>

Expected behaviour

I'd assume that it does not break the object operator and keeps it on the same line.

So instead of this:

                    @checked(collect($checkbox-
                >getValues()->get('myCheckbox'))->contains('1'))

I'd expect this:

                    @checked(collect($checkbox->getValues()->get('myCheckbox'))->contains('1'))
@onecentlin
Copy link
Owner

@sven-ahrens Hi, can you check your format setting?

I have two blade formatter installed, either won't break the syntax

圖片

@onecentlin
Copy link
Owner

@sven-ahrens I noticed that your input tag does not close properly

@sven-ahrens
Copy link
Author

@sven-ahrens I noticed that your input tag does not close properly

Hey, first of all: Thank you so much for replying.

You are right, my example is missing the closing tag but in my "real" code it doesn't. I checked that right now.

Bildschirmfoto 2022-03-04 um 17 02 23

and it turns into:

Bildschirmfoto 2022-03-04 um 17 02 51

Also I've selected your formatter:

Bildschirmfoto 2022-03-04 um 17 03 14

Bildschirmfoto 2022-03-04 um 17 03 24

Versions

  • Visual Studio Code: 1.65.0
  • Laravel Blade Snippets: v1.31.0
  • macOS: Monterey 12.2.1

@sven-ahrens
Copy link
Author

I'm not sure if it breaks because of the force-expand-multiline but I've made an easier example outside of my project and this is leading to the same result:

<div>
    <label></label>
    <input type="radio" name="test" value="1" @checked($test->works()) />
</div>
<div>
    <label></label>
    <input
        type="radio"
        name="test"
        value="1"
        @checked($test-
    >works()) />
</div>

@onecentlin
Copy link
Owner

@sven-ahrens How about change force-expand-multiline to force-aligned. This may fit your needs.

@sven-ahrens
Copy link
Author

@sven-ahrens How about change force-expand-multiline to force-aligned. This may fit your needs.

I'm coming from Vue background and I'm used to have them exactly like in my example.

I tried your version out and yes this works but it seems like it's a bug then, isnt it?

The formatter will break when having force-expand-multiline activated

@onecentlin
Copy link
Owner

@sven-ahrens Blade formatter is build based on HTML formatter. However, php syntax is not treat the same way as html.
Since the new directive @check() comes out, it is not like simple key-value attributes that recognized by HTML formatter.
I think that's why it treat php syntax -> the part > as close tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants