Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8.1 Formatting Issue #151

Open
m2cc opened this issue Jul 9, 2024 · 5 comments
Open

PHP8.1 Formatting Issue #151

m2cc opened this issue Jul 9, 2024 · 5 comments

Comments

@m2cc
Copy link

m2cc commented Jul 9, 2024

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
];
@driade
Copy link

driade commented Jul 9, 2024

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

@m2cc
Copy link
Author

m2cc commented Jul 11, 2024

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

thank you.

@driade
Copy link

driade commented Jan 8, 2025

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

@m2cc
Copy link
Author

m2cc commented Jan 9, 2025

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",
    ],

@driade
Copy link

driade commented Jan 9, 2025

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

microsoft/vscode#47983

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants