Closed phuze closed 4 months ago
Hi @phuze , good morning. I'll try to take it a look.
Hi, and thank you 🙏.
I'll mention there was a change in PHP 8 onwards, where #[
marks the beginning of an attribute. Anything else is still treated as a comment.
class VersionedObject
{
#[JsonSerialize] # attribute example
public const version = '0.0.1';
}
Thank you. Could you please elaborate this last message? We're is the bug?
My example was demonstrating the particular meaning of #[
, not suggesting a bug. I thought it was worth mentioning, incase it could be of concern when parsing within phpfmt.
Hash comments (# hello
) are otherwise parsed the same as double slash comments (// hello
).
I wonder if we could rename AlignDoubleSlashComments to simply AlignComments
, and make a small adjustment to support #
comments.
Example: https://github.com/phuze/phpfmt8/commit/df7e3637681dfdc1b269c04efba2adbe47f4d4da
I tested the change by modifying my local vscode extension, and I can confirm it seems to work as intended.
Extension file: %USERPROFILE%\.vscode\extensions\kokororin.vscode-phpfmt-1.2.10\dist\fmt.stub.php
Before:
After:
Thank you! I've integrated your code, added some tests, and it's already added to the repo. The main difference is that we shouldn't rename an existing rule, because all the people that it's already using it would lose it.
Could we add a new transformation option for hash comments, that would behave similar to AlignDoubleSlashComments?
Example: