shufo / prettier-plugin-blade

Format your blade template using Prettier
https://www.npmjs.com/package/@shufo/prettier-plugin-blade
MIT License
317 stars 8 forks source link

[Formatting Bug]: The PHP code enclosed within @php ... @endphp blocks within *.blade.php files is not formatting correctly. #276

Closed monab closed 1 month ago

monab commented 3 months ago

Version

1.14.1

Template before formatting

@foreach ($ITEMARR[1]->item as $ITEM)

{{-- active menu method --}}
@php
  $activeClass = null;
  $currentRouteName =  Route::currentRouteName();

  if ($currentRouteName === $menu->slug) {
      $activeClass = 'active';
  }
  elseif (isset($ITEM->OBJECT)) {
    if (gettype($ITEM->slug) === 'array') {
      foreach($ITEM->slug as $slug){
        if (CONDITION) {
          $activeClass = 'active';
        }
      }
    }
    else{
      if (CONDITION) {
        $activeClass = 'active';
      }
    }

  }
@endphp

Template after formatting

@foreach ($ITEMARR[1]->item as $ITEM)

{{-- active menu method --}}
@php
$activeClass = null;
$currentRouteName = Route::currentRouteName();

if ($currentRouteName === $menu->slug) {
$activeClass = 'active';
}
elseif (isset($ITEM->OBJECT)) {
if (gettype($ITEM->slug) === 'array') {
foreach($ITEM->slug as $slug){
if (CONDITION) {
$activeClass = 'active';
}
}
}
else{
if (CONDITION) {
$activeClass = 'active';
}
}

}
@endphp

Expected Behaviour

updated .prettierrc.json file for tabwidth 2 like below

  "plugins": [
    "@shufo/prettier-plugin-blade"
  ],
  "overrides": [
    {
      "files": [
        "*.blade.php"
      ],
      "options": {
        "parser": "blade",
        "tabWidth": 2
      }
    }

My Expectation: *.blade.php files should be updated with indentation properly on file save.

When applying the Format Document With.. > Prettier option, lines within the if condition are formatted with a tab width of 4, while others adhere to a tab width of 2.

Relevant log output

No response

github-actions[bot] commented 1 month ago

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