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 Bug]: Custom Directive with space around construct #930

Open
leettaylor opened this issue May 13, 2024 · 4 comments
Open

[Formatting Bug]: Custom Directive with space around construct #930

leettaylor opened this issue May 13, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@leettaylor
Copy link

leettaylor commented May 13, 2024

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 leettaylor added the bug Something isn't working label May 13, 2024
@leettaylor leettaylor changed the title [Formatting Bug]: Custom Directive [Formatting Bug]: Custom Directive with space around construct May 13, 2024
Copy link
Contributor

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 github-actions bot added the Stale label Jul 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
@leettaylor
Copy link
Author

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.

@shufo shufo removed the Stale label Aug 12, 2024
@shufo shufo reopened this Aug 12, 2024
@shufo
Copy link
Owner

shufo commented Aug 13, 2024

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

@QuentiumYT
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants