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

php statements not correctly indented

Open Wulfheart opened this issue 3 years ago • 1 comments

Slightly related to #493

Context (Environment)

Like in #493 I try to include multiple php statements in a raw php tag.

    <?php
/** @var \App\Models\Stacktrace $stacktrace */
        /** @var \App\Models\Stacktrace $stacktrace2 */
    $stacktrace = $stacktraces->first();

Current Behavior

    <?php
    /** @var \App\Models\Stacktrace $stacktrace */
    /** @var \App\Models\Stacktrace $stacktrace2 */
    $stacktrace = $stacktraces->first();
    ?>

Indentation of the <?php tag is correct as it is nested in another div.

Expected Behavior

I would like to have php line indented like this as it feels easier to read:

   <?php
        /** @var \App\Models\Stacktrace $stacktrace */
        /** @var \App\Models\Stacktrace $stacktrace2 */
        $stacktrace = $stacktraces->first();
    ?>

Wulfheart avatar Jun 30 '22 22:06 Wulfheart

Hi @Wulfheart Thanks for suggesting the style.

I also considering which indentation position we should use for Opening PHP tag, then when I looked at the coding standards such as PSR-2, there was no specification for the indentation after the Opening PHP tag, so that's why current behaviour is.

e.g.

<?php
if ($expr1) {
    // if body
} elseif ($expr2) {
    // elseif body
} else {
    // else body;
}

However Blade is more like a template than a pure PHP file, so I think it's fine to use different Style than PSR-2. I think it's not bad idea if there is closing tag after opening php tag, then it will be indent.

Maybe we should make coding standard for Blade template cause there is no coding standard for blade yet...

Anyway, if you don't mind to change the code please use @php ~ @endphp for workaround. It will be indent its content.

e.g.

   @php
        /** @var \App\Models\Stacktrace $stacktrace */
        /** @var \App\Models\Stacktrace $stacktrace2 */
        $stacktrace = $stacktraces->first();
   @endphp

If there is no indent before @php then it will unindent its content.

@php
/** @var \App\Models\Stacktrace $stacktrace */
/** @var \App\Models\Stacktrace $stacktrace2 */
$stacktrace = $stacktraces->first();
@endphp

shufo avatar Jul 01 '22 04:07 shufo

Fixed at https://github.com/shufo/blade-formatter/releases/tag/v1.30.2

shufo avatar Oct 17 '22 09:10 shufo