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

Seeking Assistance: PHP8.1 Formatting Issue #114

Closed jasonChang49 closed 11 months ago

jasonChang49 commented 11 months ago

Subject: Issue with PHP Formatting in PHP8.1

I'm writing to you as I'm currently encountering an issue with PHP formatting in PHP8.1, and I was wondering if you might be able to provide some guidance or assistance.

My current configuration is as follows:

"phpfmt.php_bin": "C:\\php8.1\\php.exe",
"phpfmt.passes": [
    "AlignDoubleArrow",
    "AlignGroupDoubleArrow",
    "AlignConstVisibilityEquals",
    "AlignEquals",
    "ReindentSwitchBlocks",
    "MergeElseIf",
    "SplitElseIf",
    "PrettyPrintDocBlocks",
    "PHPDocTypesToFunctionTypehint",
    "AlignDoubleSlashComments",
    "SpaceBetweenMethods"
]

When using PHP8.1 with this configuration, I am unable to achieve the desired alignment for the comments in my code. However, when using PHP7, everything works as expected.

For clarity, here is what I am trying to achieve:

From:

$a = 1; // Comment 1
$bb = 22;  // Comment 2
$ccc = 333;  // Comment 3

To:

$a = 1;      // Comment 1
$bb = 22;    // Comment 2
$ccc = 333;  // Comment 3

Could you kindly provide some insights or possible solutions to this? I would really appreciate your assistance.

Best regards

driade commented 11 months ago

Hi, good morning.

This is the expected behavior with "AlignEquals".

$a   = 1; // Comment 1
$bb  = 22; // Comment 2
$ccc = 333; // Comment 3

There's no rule in the code, as far as I remember, to align the comments this way.

Regards.

jasonChang49 commented 11 months ago

Thank you for your quick response. I may not have made my initial question clear enough. My apologies for any confusion.

I actually referred to the "AlignDoubleSlashComments" setting, not "AlignEquals". The configuration worked well with PHP7 and made comments alignment like this:

$a = 1;      // Comment 1
$bb = 22;    // Comment 2
$ccc = 333;  // Comment 3

But when I switched to PHP8.1, the same configuration didn't seem to work as expected. I wonder if you could provide further guidance on this specific issue?

I appreciate your help and look forward to hearing from you soon.

driade commented 11 months ago

Understood, thank you, let me take a look

driade commented 11 months ago

Hi @jasonChang49 , fixed. Please try upgrading via "phpfmt: Upgrade fmt.phar or fmt.stub.php" and let's see.

jasonChang49 commented 11 months ago

@driade Thank you so much for your assistance. The issue has been resolved and everything is functioning as expected now. Your prompt and effective help was greatly appreciated.

Wishing you a great day!