kokororin / vscode-phpfmt

Integrates phpfmt into VS Code
https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt
BSD 3-Clause "New" or "Revised" License
130 stars 30 forks source link

SpaceAroundParentheses creates adds two space chars for nested parentheses #143

Closed PrinceOfAbyss closed 5 months ago

PrinceOfAbyss commented 5 months ago

My settings JSON in regard to phpfmt formatting has the following array:

"phpfmt.passes": [
    "AlignDoubleArrow",
    "AutoPreincrement",
    "DoubleToSingleQuote",
    //"LongArray",
    "ShortArray",
    "SpaceAroundParentheses",
    "SpaceAfterExclamationMark",
],

My problem is that SpaceAroundParentheses, as its name implies, literally adds one space char after the first paren, and then adds one more before the second parent, thus resulting in two, consequent space chars between the two opening parens. Of course I may be wrong, but this seems like the most probable scenario to me.

So, if that's the case, I think that SpaceAroundParentheses should function more like SpaceAroundParenthesesInternally, in order to add a space char after (inside) the first opening paren, then add one more after (again inside) the second opening paren, and then add one before each of the closing parens (still inside them).

So to give you and example of the problem, this:

        if ( ( $min <= $cart_item['data']->get_weight() ) && ( $cart_item['data']->get_weight() < $max ) ) {

after formatting becomes like this:

        if (  ( $min <= $cart_item['data']->get_weight() ) && ( $cart_item['data']->get_weight() < $max ) ) {
driade commented 5 months ago

Hi @PrinceOfAbyss , thank you very much.

This is a very old rule many people use and we can't change neither its name nor its behavior. It's totally optional to use it or not.

If this rule doesn't fit your needs, maybe you could propose another one to be implemented.

PrinceOfAbyss commented 5 months ago

Hello @driade , thank you for your reply.

Since this rule can't be changed, the next best thing would be a new rule along the lines I mentioned in my first post. That is, something that will add spaces only inside two parentheses, named ie. SpaceInsideParentheses or SpaceAroundParenthesesInternally, etc...

Something that will change this: if (($min <= $cart_item['data']->get_weight()) && ($cart_item['data']->get_weight() < $max)) {

to this: if ( ( $min <= $cart_item['data']->get_weight() ) && ( $cart_item['data']->get_weight() < $max ) ) {

but not to this: if ( ( $min <= $cart_item['data']->get_weight() ) && ( $cart_item['data']->get_weight() < $max ) ) {

Do you think this can be achieved?

driade commented 5 months ago

Hmm, now that I see what you mean I think that it's clear there's a bug in the current rule, where we've two spaces where it surely must be one. Please let me check.

PrinceOfAbyss commented 5 months ago

Exactly that @driade! Thank you very much!

What's interesting about the bug is that it happens only on the opening side, not the closing one: https://prnt.sc/in0d5iay6aO1

driade commented 5 months ago

There you've, it should be already fixed.

PrinceOfAbyss commented 5 months ago

@driade any ETA on this being released as an update to VS.Code?

driade commented 5 months ago

I'm not entirely sure about how the changes are synced to VSCode. From what I understand, it's fast, but I'm uncertain about the specifics.

kokororin commented 5 months ago

The automatic update script has some issues; version 1.2.1 has been released now.

PrinceOfAbyss commented 5 months ago

Indeed the bug is corrected now! Thanks @kokororin