vscode-phpfmt icon indicating copy to clipboard operation
vscode-phpfmt copied to clipboard

PHP8.1 Formatting Issue

Open m2cc opened this issue 1 year ago • 5 comments

Subject: Issue with PHP Formatting in PHP8.1, the plugin version is 1.2.12 我目前的配置如下:

"phpfmt.passes": [
        "SplitElseIf",
        "AlignEquals",
        "AlignGroupDoubleArrow",
        "AlignPHPCode",
        "AlignDoubleArrow",
        "AlignComments"
    ],

before:

$arr = [
  'a' => 1, //xxxx
  'aa' => 1,   // xxxx
  'aaaa' => 1,// xxxxxx
  'aaaaaa' => 1, // x
];

after format, it becomes like this:

$arr = [
    'a' => 1, //xxxx
    'aa' => 1, // xxxx
    'aaaa' => 1, // xxxxxx
    'aaaaaa' => 1, // x
];

exexpected: align comments and alian keys

$arr = [
    'a'      => 1, //xxxx
    'aa'     => 1, // xxxx
    'aaaa'   => 1, // xxxxxx
    'aaaaaa' => 1, // x
];

m2cc avatar Jul 09 '24 10:07 m2cc

Hi @m2cc , I'm on this. Related to https://github.com/driade/phpfmt8/issues/62

driade avatar Jul 09 '24 10:07 driade

Hi @m2cc , I'm on this. Related to driade/phpfmt8#62

thank you.

m2cc avatar Jul 11 '24 02:07 m2cc

Hi @m2cc . Let's see if the lastest release fixes this. Thanks!

driade avatar Jan 08 '25 12:01 driade

Hi @m2cc . Let's see if the lastest release fixes this. Thanks!你好 。让我们看看最新版本是否修复了这个问题。谢谢!

yes, you fixed this, thank you!!

but when the array keys is chinese,it not works。

the code :

$arr = [
    '键一' => 4, // 1
    '键2' => 11, // xxxx
    '键三' => 12, // xxxx
    '其它长键' => 6445, // xxxx
    'absc' => 6445, // xxxx
];

after format, it becomes like this:

$arr = [
    '键一'   => 4, // 1
    '键2'   => 11, // xxxx
    '键三'   => 12, // xxxx
    '其它长键' => 6445, // xxxx
    'absc' => 6445, // xxxx
];

expected: align comments and align keys。

My current configuration is as follows:

"phpfmt.passes": [
        "AlignEquals",
        "AlignSuperEquals",
        "AlignPHPCode",
        "AlignDoubleArrow",
        "AlignGroupDoubleArrow",
        "AlignComments",
        "AutoSemicolon",
        "ClassToStatic",
        "MergeElseIf",
        "OrderAndRemoveUseClauses",
        "PrettyPrintDocBlocks",
        "PSR2EmptyFunction",
        "ReindentAndAlignObjOps",
        "ReindentSwitchBlocks",
        "ReindentEnumBlocks",
        "RemoveIncludeParentheses",
        "RemoveSemicolonAfterCurly",
        "ShortArray",
        "SmartLnAfterCurlyOpen",
        "SortUseNameSpace",
        "SpaceBetweenMethods",
        "TrimSpaceBeforeSemicolon",
        "WrongConstructorName",
    ],

m2cc avatar Jan 09 '25 07:01 m2cc

Hi @m2cc I've been checking this and I think that the problem is mixing chinese characters with standard ones.

The "space" we use to fill the lines comes from standard " ". But chinese characters are wider than the standard (monospaced) ones, so when we fill the lines with spaces, arrows get visually misaligned.

Please check the screenshot where you may see it.

Captura de pantalla 2025-01-09 a las 9 54 00

I've read overthere that people have similar problems

https://github.com/Microsoft/vscode/issues/47983

If chinese characters would be rendered as 2 wide standard chars we could make the calculations to perfectly align the code.

driade avatar Jan 09 '25 09:01 driade