Closed bakerkretzmar closed 1 month ago
Thanks for the report. Are you just using the defaults, or have you also configured it to use Pint to format PHP inside directives? Thanks!
Not using Pint, pretty much the defaults I think. Here's my Prettier config in case it's helpful but it's mostly not related to Blade:
{
"htmlWhitespaceSensitivity": "ignore",
"printWidth": 140,
"singleQuote": true,
"tabWidth": 4,
"importOrder": [
"^@(?!/)(.*)$",
"^@/(.*)$",
"^[./]"
],
"importOrderSortSpecifiers": true,
"plugins": [
"@trivago/prettier-plugin-sort-imports",
"prettier-plugin-blade",
"prettier-plugin-tailwindcss"
],
"pluginSearchDirs": false,
"overrides": [
{
"files": "*.yml",
"options": {
"tabWidth": 2
}
},
{
"files": [
"*.blade.php"
],
"options": {
"htmlWhitespaceSensitivity": "css",
"parser": "blade"
}
}
]
}
That is very helpful, thank you!
Got the same issue for the following statements:
@php(($count = WC()->cart->get_cart_contents_count()))
@php(($bg = get_field('populated_bg_color') === 'gray' ? ' bg-gray-100 my-2 my-lg-5' : ''))
@RobertBlaauwendraad Thanks for those examples. I was able to reproduce with that input; I'll work on a fix (hopefully ready sometime this upcoming weekend) 🙌
Fix available in v2.1.17
Given the following code, the formatter toggles parentheses around the variable assignment in the
@if
every time it runs:So it switches back and forth between these:
It seems to be related to chaining something on after a method call, because this is fine:
But this also triggers this issue:
The parentheses aren't necessary, so I would expect it to remove them if they're there, or at least not add them.