kokororin / vscode-phpfmt

Integrates phpfmt into VS Code
https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt
BSD 3-Clause "New" or "Revised" License
129 stars 30 forks source link

Function Format #152

Closed pushline closed 3 weeks ago

pushline commented 1 month ago

In my laravel project, sometimes i do custom queries inside the where function. The problem is, the opening brace is being misaligned within the closing brace. It happens on leftJoin queries aswell and etc, any function that opens braces within.

How it is:

$isBanned = Ban::where('banned_id', $user->id)
    ->where(function ($query)
{
        $query->whereNull('expiry_date')
            ->orWhere('expiry_date', '>', now());
    })
    ->exists();

How should be:

$isBanned = Ban::where('banned_id', $user->id)
    ->where(function ($query)
    {
        $query->whereNull('expiry_date')
            ->orWhere('expiry_date', '>', now());
    })
    ->exists();

More examples: https://imgur.com/a/WXhdm6g My passes:

"phpfmt.passes": [
    "UpgradeToPreg",
    "ReindentSwitchBlocks",
    "PSR2EmptyFunction",
    "MergeElseIf",
    "ConvertOpenTagWithEcho",
    "AddMissingParentheses",
    "AlignPHPCode",
    "AllmanStyleBraces",
  ],

I don't know if theres any passes that fix it, if there is please comment it. Thanks for your attention.

driade commented 1 month ago

Hi! It seems the problem comes with the pass "AllmanStyleBraces". If you remove it you'd get a proper formatting, though it may not be the one you want.

pushline commented 1 month ago

Yeah it goes to function ($query) {. It isn't exactly what i needed but its better than those air-hanging braces.