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

Comment Align after format #124

Closed luxorwannabe closed 8 months ago

luxorwannabe commented 9 months ago

Dear All,

When I try to format my php code with phpfmt - PHP formatter (visual studio code)from:

function test( $test ) {

   // Check for $test
   if ( $test ) {
       echo 'TOS';
   }
   else {
       echo 'TUS';
   }

}

It will become:

function test( $test ) {

// Check for $test
   if ( $test ) {
       echo 'TOS';
   }
   else {
       echo 'TUS';
   }

}

As you can see the comment // Check for $test is not aligned vertically with IF statement. How to fix this?

Thanks

driade commented 9 months ago

Thanks @luxorwannabe I'll check it

driade commented 8 months ago

May you please share you configuration for the package? I can't reproduce this on my side (the comment gets correctly aligned).

Thanks.

luxorwannabe commented 8 months ago

The wrong alignment is comment on top "if", "switch". Btw, I didnt change any configs, I use it as is.

Please copy paste this and try in your side:

function test( $test )
{

    // Check for $test
    if ( $test ) {
        echo 'TOS';
    } else {
        echo 'TUS';
    }

}

function testA()
{

    $favcolor = 'red';

    // What is my fav color?
    switch ( $favcolor ) {
        case 'red':
            echo 'Your favorite color is red!';
            break;
        case 'blue':
            echo 'Your favorite color is blue!';
            break;
        default:
            echo 'Your favorite color is neither red, blue, nor green!';
    }

}
driade commented 8 months ago

I get this

<?php

function test($test)
{

    // Check for $test
    if ($test) {
        echo 'TOS';
    } else {
        echo 'TUS';
    }

}

function testA()
{

    $favcolor = 'red';

    // What is my fav color?
    switch ($favcolor) {
        case 'red':
            echo 'Your favorite color is red!';
            break;
        case 'blue':
            echo 'Your favorite color is blue!';
            break;
        default:
            echo 'Your favorite color is neither red, blue, nor green!';
    }

}

PHP 8.2. This is my config (I use Sublime Text, but under the hood the package is the same)

{
    "autocomplete": false,
    "autoimport": false,
    "excludes": [

    ],
    "format_on_save": true,
    "passes":
    [
        "AlignDoubleArrow",
        "AlignPHPCode",
        "SpaceAfterExclamationMark",
        "AlignConstVisibilityEquals",
        "AutoSemicolon",
        "ConvertOpenTagWithEcho",
        "AlignEquals",
        "MergeNamespaceWithOpenTag",
        "RemoveSemicolonAfterCurly",
        "RestoreComments",
        "ShortArray",
        "ExtraCommaInArray",
        "AlignDoubleSlashComments"
    ],
    "php_bin": "/usr/local/bin/php",
    "psr1": false,
    "psr1_naming": true,
    "psr2": true,
    "readini": false,
    "smart_linebreak_after_curly": false,
    "version": 4,
    "wp": false,
}
luxorwannabe commented 8 months ago

Hi thanks for sharing your config, this video will show you the details: Video Demo

luxorwannabe commented 8 months ago

SOLVED, I just remove SpaceAroundControlStructures from passes. Thak you very much for your help :)