shufo / prettier-plugin-blade

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

[Formatting Bug]: Formatter add unnecessary coma, which break the code #275

Closed westtrade closed 4 months ago

westtrade commented 6 months ago

Version

@shufo/prettier-plugin-blade@1.14.1

Template before formatting

@php(
    $employees_list = array_map(function ($employee) {
        return [
            'name' => $employee['name'],
            'value' => $employee['id'],
        ];
    }, $employees->toArray())
)

Template after formatting

@php(
    $employees_list = array_map(function ($employee) {
        return [
            'name' => $employee['name'],
            'value' => $employee['id'],
        ];
    }, $employees->toArray()), // <- add unnnecessary comma to the end, which break the code
)

Expected Behaviour

Don't touch PHP code at all

Relevant log output

No response

shufo commented 6 months ago

Thanks for creating the issue @westtrade I'll look into it.

To workaround, you can use @php ~ @endphp directive.

 $  ./bin/blade-formatter.js test.blade.php
@php
    $employees_list = array_map(function ($employee) {
        return [
            'name' => $employee['name'],
            'value' => $employee['id'],
        ];
    }, $employees->toArray());
@endphp

or use --trailing-comma-php option

 $  yarn run prettier __tests__/fixtures/test.blade.php --trailing-comma-php=false
yarn run v1.22.19
$ prettier --plugin @shufo/prettier-plugin-blade __tests__/fixtures/test.blade.php --trailing-comma-php=false
@php(
    $employees_list = array_map(function ($employee) {
        return [
            'name' => $employee['name'],
            'value' => $employee['id']
        ];
    }, $employees->toArray())
)
github-actions[bot] commented 4 months 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