As I configured PHP:Format:Rules for my need. I encounter this weird moving comma on new line. Is this a bug? If not can you point me what formatting rules that I need to change? Thanks.

Current behavior:

What I want:

Environment:
PHP Tools: v1.45.15260

Version: 1.88.0
Commit: 5c3e652f63e798a5ac2f31ffd0d863669328dc4c
Date: 2024-04-03T13:25:57.039Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Linux x64 6.5.0-27-generic

    Hi,

    Thank you for the post. This looks like a bug. I don't think we have a rule for this, let me check that and get back to you.

    we can't reproduce this on our end. May I ask for a whole file and current formatting setting (settings.json)

    Thank you!

    Here is my formatting settings:

    {
    "[php]": {
            "editor.defaultFormatter": "DEVSENSE.phptools-vscode"
        },
        "phpTools.language": "en",
        "php.format.codeStyle": "Laravel",
        "php.inlayHints.types.return": false,
        "php.inlayHints.parameters.enabled": false,
        "php.completion.parameters": "parentheses",
        "php.format.rules.keepControlStatementsOnOneLine": true,
        "php.format.rules.spaceAfterCast": true,
        "php.format.rules.alignConsecutiveAssignments": false,
        "php.format.rules.spaceWithinArrayInitilizersParens": false,
        "php.format.rules.arrayInitializersNewLineAfterLastElement": true,
        "php.format.rules.arrayInitializersNewLineBeforeFirstElement": true,
        "php.format.rules.groupUseNewLineBeforeFirstDeclaration": false,
        "php.format.rules.switchStatementNewLineAfterLeftParen": true,
        "php.format.rules.callParametersNewLineBeforeRightParen": true,
        "php.format.rules.callParametersNewLineAfterLeftParen": true,
        "php.format.rules.whileStatementNewLineAfterLeftParen": true,
        "php.format.rules.ifStatementNewLineBeforeRightParen": true,
        "php.format.rules.openBraceOnNewLineForFunctions": true,
        "php.format.rules.ifStatementNewLineAfterLeftParen": true,
        "php.format.rules.openBraceOnNewLineForBlocks": false,
        "php.format.rules.declParametersNewLineAfterLeftParen": true,
        "php.format.rules.whileStatementNewLineBeforeRightParen": true,
        "php.format.rules.endWithNewLine": false,
        "php.format.rules.chainedMethodCallsSemicolonOnNewLine": false,
        "php.format.rules.declParametersWrap": "onEveryItem",
        "php.format.rules.spaceAroundConcatenation": true,
        "php.format.rules.spaceBeforeColonInReturnType": false,
        "php.format.rules.spaceAfterUnaryNot": false,
        "php.format.rules.removeReduntandClosingTag": true,
        "php.format.rules.addCommaAfterLastDeclParameter": false,
        "php.format.rules.addCommaAfterLastArrayElement": true,
        "php.format.rules.arrayInitializersWrap": "onEveryItem",
        "php.format.rules.spaceWithinBrackets": false,
        "php.format.rules.spaceWithinForParens": true,
        "php.format.rules.callParametersWrap": "onEveryItem",
        "php.format.rules.addCommaAfterLastCallParameter": false,
        "php.format.rules.alignConstants": false,
        "php.format.rules.alignEnumCases": true,
        "php.format.rules.alignMatchArmBodies": false,
        "php.format.rules.chainedMethodCallsWrap": "always",
        "php.format.rules.arrayInitializersAlignKeyValuePairs": false,
        "php.completion.showParameters": true,
        "php.format.rules.declCompactEmptyBody": false,
        "php.format.rules.spaceBeforeParenthesesInControlStatements": true,
        "php.format.rules.declKeepRightParenAndOpenBraceOnOneLine": true,
        "php.format.rules.forStatementNewLineBeforeRightParen": true,
        "php.format.rules.switchStatementNewLineBeforeRightParen": true,
        "php.hover.parametersFullName": true,
        "php.completion.showDeprecated": "showStrikethrough",
        "php.problems.excludeGitIgnore": true,
        "php.format.rules.indentBraces": false,
        "php.codeLens.enabled": false,
        "php.format.rules.declParametersNewLineBeforeRightParen": false,
        }

    I observed that the issue shows up when the parameters has multiple lines. Here is the example file:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Support\Carbon;
    
    class Test
    {
        public function set($key, $value, $options)
        {
            return $this;
        }
    
        public function bar()
        {
            return $this;
        }
    
        public function foo()
        {
            $date = Carbon::now();
    
            // Here it is not working.
            $this->set(
                $date->copy()
                    ->endOfDay()
                ,
                $date->copy()
                    ->startOfDay()
                ,
                ['timezone' => 'UTC']
            )
                ->bar();
        }
    
        public function zoo()
        {
            $date = Carbon::now();
    
            // Here it is working.
            $this->set(
                $date->copy(),
                $date->copy(),
                ['timezone' => 'UTC']
            )
                ->bar();
        }
    
        public function baz()
        {
            // Here it is working fine.
            $this->set(
                'parameters',
                'value',
                ['option' => 'value']
            )
                ->bar();
        }
    }

    Hi,

    Perfect. Thank you so much! It's repeatable now, it will be fixed ASAP.

      Fixed. Thank you, it will be released in the next pre-release.

      Write a Reply...