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

Extra Spaces in Namespaced Attributes and Traits Formatting with phpfmt #132

Closed ferhado closed 7 months ago

ferhado commented 7 months ago

The formatter is introducing extra spaces when formatting classes that use namespace prefixes in attribute and trait declarations. This issue specifically arises with namespaced attributes and when multiple traits with namespace prefixes are used in a class. The formatting is correct when namespace prefixes are not used.

Steps to Reproduce

  1. Format a PHP class using namespaced attributes and multiple traits.
  2. Compare the output with a similar class using non-namespaced attributes and traits.

Current Behavior

With namespaced attributes, the formatter adds extra spaces, as demonstrated below:

class ExampleClass {
  use Traits\ExampleTrait1 , Traits\ExampleTrait2 , Traits\ExampleTrait3;

  #[ORM\Id, ORM\GeneratedValue , ORM\Column ]
  private ?int $id = null;
}

However, when using non-namespaced attributes and traits, the formatter behaves as expected:

class ExampleClass {
  use ExampleTrait1, ExampleTrait2, ExampleTrait3;

  #[Id, GeneratedValue, Column]
  private ?int $id = null;
}

Expected Behavior

The formatter should not introduce extra spaces when namespace prefixes are used. The expected, correctly formatted code should look like this:

class ExampleClass {
  use Traits\ExampleTrait1, Traits\ExampleTrait2, Traits\ExampleTrait3;

  #[ORM\Id, ORM\GeneratedValue, ORM\Column]
  private ?int $id = null;
}
driade commented 7 months ago

Thanks @ferhado, already fixed.

ferhado commented 7 months ago

Confirmed, the issue has been resolved. Thank you for the quick fix!