-
-
Notifications
You must be signed in to change notification settings - Fork 139
Update php-parser, fix unary snapshot tests, and make multiple fixes for attribute formatting. #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update php-parser, fix unary snapshot tests, and make multiple fixes for attribute formatting. #2502
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4922,9 +4922,9 @@ class Foo | |||||
|
|
||||||
| public function emptyMethod(/* comments */) {} | ||||||
|
|
||||||
| abstract public function sortByName(/* bool $useNaturalSort = false */); /* comment */ | ||||||
| abstract public function sortByName(/* bool $useNaturalSort = false */); | ||||||
|
|
||||||
| /* comment */ /* comment */ protected static $foo; /* comment */ | ||||||
| /* comment */ /* comment */ /* comment */ protected static $foo; /* comment */ | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Everything looks correct, except of this part. Some comments moved into wrong places.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't feel quite right either? So the unformatted was this: We have 4 comment blocks attached to the property in total. One before the declaration, 2 inside of it, and 2 after. abstract public function sortByName(/* bool $useNaturalSort = false */);
/* comment */ protected /* comment */ static /* comment */ $foo /* comment */;
public function foo( // Comment
) {}Previously it formatted to this, which emits the leading comment in the spot and emits the inner comments before the declaration. abstract public function sortByName(/* bool $useNaturalSort = false */); /* comment */ ← stolen
/* comment */ /* comment */ protected static $foo; /* comment */ ← 1 comment missingIt just fixed the leading comment getting emitted in the wrong spot, but did not modify the behaviour of comments getting placed in between property keywords. abstract public function sortByName(/* bool $useNaturalSort = false */);
/* comment */ /* comment */ /* comment */ protected static $foo; /* comment */ ← all 4 preservedI guess what it really comes down to is: Do we want to allow comments on property keywords or not. In my mind, that doesn't make much sense at all (If I saw someone putting PHPDoc between the modifier and the property I'd be asking wtf they are doing), so I preserve them but emit them as leading comments on the property declaration. In any case it's an improvement over it getting attached to the previous node.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll note as well supporting preservation of property keywords gets a bit gnarlier when you consider we'd want to do it for constants as well, and there are a lot of other modifiers as well (types, readonly, attributes, multi property declarations etc). |
||||||
|
|
||||||
| public function foo() {} // Comment | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| use App\Support\Attributes\Description; | ||
|
|
||
| enum SalutationEnum: string | ||
| { | ||
| #[Description('Mr.')] | ||
| case MR = 'mr'; | ||
|
|
||
| #[Description('Mrs.')] | ||
| case MRS = 'mrs'; | ||
|
|
||
| #[Description('Miss')] | ||
| case MISS = 'miss'; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see that something is messed up with comments. Why did this comment change its position?
Do you know whether it's a fault of the PHP parser or your PR?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the changes I made to comment/attribute formatting (Item 1 in my snapshot changes listed in the PR description).
So this is the raw unformatted code
} // Testing S #[S] //Testing S-T #[T] //Testing TThis is the old snapshot
And my udpated snapshot
} ← no stray comment // Testing S #[S] //Testing S-T ← stays between #[S] and #[T] #[T] //Testing T ← comment stays with #[T] private function u()It's kind of hard to tell in the git diff that's for sure. One of the negatives of such a huge snapshot is that the input/output are hundreds of lines apart when looking at the snapshot.