Closed nelson6e65 closed 12 months ago
.prettierrc.json
{
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"arrowParens": "always",
"overrides": [
{
"files": ["*.php"],
"options": {
"phpVersion": "7.2",
"tabWidth": 4,
"printWidth": 120
}
},
{
"files": ["*.blade.php"],
"options": {
"phpVersion": "7.2",
"trailingCommaPHP": false,
"tabWidth": 2,
"printWidth": 120,
"parser": "blade",
"sortHtmlAttributes": "vuejs",
"wrapAttributes": "force-expand-multiline"
}
}
],
"plugins": ["@prettier/plugin-php", "@shufo/prettier-plugin-blade"]
}
It happens even in a @php
directive:
@php
echo Form::select(
'refundType',
REFUND_TYPES,
$data->refundType ?? null,
[
'class' => 'form-control refundType',
'required' => 'required',
] + ($refundId ? ['disabled' => 'true'] : []),
);
@endphp
In a normal PHP file, the trailing comma it's removed:
public function test()
{
$refundId = null;
echo Form::select(
'refundType',
REFUND_TYPES,
null,
[
'class' => 'form-control refundType',
'required' => 'required',
] + ($refundId ? ['disabled' => 'true'] : [])
);
}
Thanks @nelson6e65.
Maybe we should support trailingCommaPHP
and respect phpVersion
for compatibility.
Added --trailing-comma-php
option at https://github.com/shufo/prettier-plugin-blade/releases/tag/v1.12.0.
You can disable trailing comma by setting like
.prettierrc.json
"options": {
~~
"trailingCommaPHP": false,
}
Thanks a lot! 🎉
And 1.13 with phpVersion
?
@nelson6e65
And 1.13 with phpVersion?
Yes, this package will respect phpVersion
option if exists.
Version
1.8.13 | 1.11.1
Template before formatting
Template after formatting
Expected Behaviour
It should not add the trailing comma for PHP 7.2:
Relevant log output