Stillat / blade-parser-typescript

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.
https://stillat.com
MIT License
90 stars 3 forks source link

Does the plugin format indentation? #72

Closed ralphjsmit closed 10 months ago

ralphjsmit commented 1 year ago

I noticed that I am still getting indentation issues that are not being fixed by the plugin. I already updated the "useTabs": true, in the .prettierc.

Thereby a question, does the plugin format indentation, like tabs/spaces?

I do not necessarily care about whatever version the plugin chooses, as long as it always corrects it to one version.

Thanks!

Indentation
JohnathonKoster commented 1 year ago

Would you be able to provide the text version of the template that is exhibiting the issue? Sometimes its the surrounding context that does weird things, and it really helps to resolve the issues quickly :)

ralphjsmit commented 1 year ago

Of course!

For example, this file:

@php
    use Illuminate\Support\Collection;
@endphp

@props([
    'breadcrumbs',
])

<div {{ $attributes->class(['filament-breadcrumbs flex-1']) }}>
    <ul
        @class([
            'hidden items-center gap-4 text-sm font-medium lg:flex',
            'dark:text-white' => config('filament.dark_mode'),
        ])
    >
        @foreach ($breadcrumbs as $action => $label)
            <li>
                <button
                    type="button"
                    wire:click="{{ $action }}"
                    @class([
                        'text-gray-500' => $loop->last && (! $loop->first),
                        'dark:text-gray-300' => ((! $loop->last) || $loop->first) && config('filament.dark_mode'),
                        'dark:text-gray-400' => $loop->last && (! $loop->first) && config('filament.dark_mode'),
                    ])
                >
                    {{ $label }}
                </button>
            </li>

            @if (! $loop->last)
                <li
                    @class([
                        'h-6 -skew-x-12 border-r border-gray-300',
                        'dark:border-gray-500' => config('filament.dark_mode'),
                    ])
                ></li>
            @endif
        @endforeach
    </ul>
</div>
Scherm­afbeelding 2023-07-08 om 18 54 50
ralphjsmit commented 1 year ago

I already ran the formatter earlier on the complete project. Then, PhpStorm updated the indentation (which I don't care about, because the code style fixer should fix it anyway before PR merge). So I ran the formatter again and the indentation change stayed visible. I would have expected the indentation change to be reverted to how the code originally was in the previous commit.

JohnathonKoster commented 1 year ago

Thanks for the extra information!

I'm having trouble getting it to reapply the indentation (the formatter should be removing extraneous whitespace) - will keep trying to figure out how to get it to happen, though.

The formatter was intended to be used with spaces instead of tabs, I wonder if that's contributing 🤔

ralphjsmit commented 1 year ago

Hey! I tried updating useTabs: false and that didn't work either. It seems to just not do anything.

It's a private repo, but I can give you temporary access. Would that be helpful?

Thanks!

JohnathonKoster commented 1 year ago

Hey! I tried updating useTabs: false and that didn't work either. It seems to just not do anything.

It's a private repo, but I can give you temporary access. Would that be helpful?

Thanks!

That might help, for sure!

ralphjsmit commented 1 year ago

@JohnathonKoster I've just sent you an invite to the repo! Ideally I would like to have the formatter fix the indentation and force one consistent indentation, even though the indentation changed by PhpStorm. E.g. changing indentation by PhpStorm in Blade files is an issue we also have on another big project with multiple devs, because that blows up PRs 😬😄

JohnathonKoster commented 1 year ago

Sounds great; thank you! I'll poke around this weekend and see if I can track down what's happening :)

howdu commented 1 year ago

Not sure if this is related but after switching from @shufo/prettier-plugin-blade I'm finding the @class directive is not getting indented correctly.

The deeper the nesting the more the the indention is getting excessively indented.

E.g

<div>
    <div>
        <div>
            <div>
                <div
                    @class([
                        'grid',
                        'gap-2' => $key === 'secondary',
                        'gap-4' => $key !== 'secondary'
                    ])
                >
                    <div>Test</div>
                </div>
            </div>
        </div>
    </div>
</div>
Screenshot 2023-08-04 at 11 40 32 Screenshot 2023-08-04 at 11 43 15
marynazinchenk commented 10 months ago

Not sure if this is related but after switching from @shufo/prettier-plugin-blade I'm finding the @Class directive is not getting indented correctly.

The deeper the nesting the more the the indention is getting excessively indented.

E.g

<div>
    <div>
        <div>
            <div>
                <div
                    @class([
                        'grid',
                        'gap-2' => $key === 'secondary',
                        'gap-4' => $key !== 'secondary'
                    ])
                >
                    <div>Test</div>
                </div>
            </div>
        </div>
    </div>
</div>

Screenshot 2023-08-04 at 11 40 32 Screenshot 2023-08-04 at 11 43 15

same problem with @include directive

JohnathonKoster commented 10 months ago

@marynazinchenk Would you be able to provide your prettier settings, blade formatter settings (if configured), version numbers, as well as the original document as an attachment?

I've yet to reproduce this on my end. Thanks!