Keep multiline Blade directive arguments stable across runs - #477
Conversation
|
@lazerg <div @class([
'inline-block',
'border-b-2',
'border-gray-700',
'bg-green-100' => $customer->paid,
'bg-red-100' => !$customer->paid,
'p-2',
'text-right',
'align-top',
'text-lg',
])>
Has it been paid yet?
</div>Second run: <div @class([
'inline-block',
'border-b-2',
'border-gray-700',
'bg-green-100' => $customer->paid,
'bg-red-100' => !$customer->paid,
'p-2',
'text-right',
'align-top',
'text-lg',
])>
Has it been paid yet?
</div>Tirth run: <div @class([
'inline-block',
'border-b-2',
'border-gray-700',
'bg-green-100' => $customer->paid,
'bg-red-100' => !$customer->paid,
'p-2',
'text-right',
'align-top',
'text-lg',
])>
Has it been paid yet?
</div>the 4th run puts the block back where it should be. The {
"printWidth": 100,
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"bracketSpacing": false,
"bracketSameLine": false,
"plugins": ["prettier-plugin-blade", "prettier-plugin-tailwindcss"],
"tailwindConfig": "tailwind.config.js",
"overrides": [
{
"files": [
"*.blade.php"
],
"options": {
"parser": "blade"
}
}
]
}I tried to override the blade file options with "options": {
"parser": "blade",
"bladeBlankLinesAroundDirectives": "preserve",
"bladeDirectiveArgSpacingOverrides": ["if", "elseif", "unless", "while", "for", "foreach", "forelse", "switch", "case", "class"]
}Adding 'class' to the default settings. But alas... For now I just rollback that one file. Anyway, your commit fixed the other anomalities for which my thanks 🏆 |
|
Thanks for testing it. I could reproduce this one, and it turned out to be a different bug. Prettier wraps the One thing on the config: Pint does not read your |
When the Blade formatter reformats a directive argument, it re-indents the continuation lines to the directive's column, but it never removes the indentation the previous run put there. With a ruleset that includes
array_indentationthis goes unnoticed, since php-cs-fixer collapses the argument back to column zero first. With a Blade-only setup ("preset": "empty"plusPint/laravel_blade) no fixer does that, so every run pushes a nested@class([...])or@include(..., [...])another level to the right andpint --testnever passes.This strips the directive's own indentation from the argument before formatting it, so re-indenting afterwards puts the lines back where they were instead of stacking on top.
Fixes #476