valeryan / vscode-phpsab

Php Sniffer and Beautifier for VS Code
https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab
MIT License
58 stars 12 forks source link

Formatter breaks single line comment blocks #126

Closed GamesmenJordan closed 5 months ago

GamesmenJordan commented 5 months ago

Whenever there is a single line comment block such as

/** @var Object $foo */
$foo = bar();

The formatter breaks the single line comment block into multiple lines

/** 
 * @var Object $foo
 */
$foo = bar();

Additionally, it doesn't respect the indentation of the comment block and also doesn't correct it on multiple runs of the formatter, resulting in the following:

try {
    /** @var Object $foo */
    $foo = bar();
}

Becomes...

try {
    /** 
 * @var Object $foo
*/
    $foo = bar();
}
jonathanbossenger commented 5 months ago

@GamesmenJordan could I ask what PHP Coding Standard you are using?

The style of comments you're using here is typically used for multi-line comments, not single lines. Single-line comments are typically a double forward slash in PHP //

https://www.php.net/manual/en/language.basic-syntax.comments.php

So my guess here is that the coding standard in use (or if you've not set one, then the default PHP coding standard installed with PHPCS) is what's forcing this.

valeryan commented 5 months ago

This extension does not do the actual formatting. Phpcs and Phpcbf does the formatting. They apply the fixers you have configured. If you think you have your standards correct to allow a php multi line comment inline and a bug is present in Phpcbf you will have to go make an issue here https://github.com/PHPCSStandards/PHP_CodeSniffer/