blade-formatter icon indicating copy to clipboard operation
blade-formatter copied to clipboard

[Formatting Bug]: Custom Directive with space around construct

Open leettaylor opened this issue 1 year ago • 12 comments

Version

1.41.1

Template before formatting

{{-- Not Working --}}

@loop ($items as $item)
    {{ $item }}
@endloop

@loopelse ($items as $item)
    {{ $item }}
@loopempty
    No items
@endloopelse

@loop($items as $item)
    {{ $item }}
@endloop

@loopelse($items as $item)
    {{ $item }}
@loopempty
    No items
@endloopelse

{{-- Working --}}

@foreach ($items as $item)
    {{ $item }}
@endforeach

@forelse ($items as $item)
    {{ $item }}
@empty
    No items
@endforelse

@foreach($items as $item)
    {{ $item }}
@endforeach

@forelse($items as $item)
    {{ $item }}
@empty
    No items
@endforelse

Template after formatting

{{-- Not Working --}}

@loop ($items as $item)
{{ $item }}
@endloop

@loopelse
    ($items as $item)
    {{ $item }}
    @loopempty
    No items
@endloopelse

@loop($items as $item)
{{ $item }}
@endloop

@loopelse($items as $item)
    {{ $item }}
    @loopempty
    No items
@endloopelse

{{-- Working --}}

@foreach ($items as $item)
    {{ $item }}
@endforeach

@forelse ($items as $item)
    {{ $item }}
@empty
    No items
@endforelse

@foreach ($items as $item)
    {{ $item }}
@endforeach

@forelse($items as $item)
    {{ $item }}
@empty
    No items
@endforelse

Expected Behaviour

The input should remain unchanged.

@loop ($items as $item)
    {{ $item }}
@endloop

@loopelse ($items as $item)
    {{ $item }}
@loopempty
    No items
@endloopelse

When a custom directive has a space around the construct the formatter moves the construct onto a new line which causes a syntax error. It also doesn't correctly apply indentation inside of the custom directive.

It works perfectly fine for a @foreach.

Relevant log output

No response

leettaylor avatar May 13 '24 13:05 leettaylor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jul 13 '24 01:07 github-actions[bot]

This is still an issue.

@shufo I don't mind having a go trying to resolve it if you can point me in the right direction.

leettaylor avatar Jul 23 '24 06:07 leettaylor

@leettaylor Thanks for creating the issue and your offer. I think this behaviour should be fixed to allow one space around construct or delete space if it is not necessary.

It might be difficult to point where it should be fixed so I'll take a look around custom directive formatting section.

shufo avatar Aug 13 '24 17:08 shufo

Looks like I submitted a similar issue but with real directives #941, the following code has the same indentation issue

@if ($i >= 1)
  @break
@endif

QuentiumYT avatar Sep 26 '24 09:09 QuentiumYT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Nov 26 '24 02:11 github-actions[bot]

Still an issue

leettaylor avatar Nov 26 '24 11:11 leettaylor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jan 27 '25 01:01 github-actions[bot]

Still an issue

QuentiumYT avatar Jan 27 '25 08:01 QuentiumYT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Mar 29 '25 02:03 github-actions[bot]

Still an issue

QuentiumYT avatar Mar 30 '25 13:03 QuentiumYT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar May 30 '25 02:05 github-actions[bot]

Still an issue

QuentiumYT avatar May 30 '25 05:05 QuentiumYT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jul 30 '25 02:07 github-actions[bot]

Still an issue

QuentiumYT avatar Jul 30 '25 12:07 QuentiumYT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Sep 30 '25 02:09 github-actions[bot]

Still an issue

QuentiumYT avatar Sep 30 '25 07:09 QuentiumYT