Skip to content

fix: keep a comment after the last parameter on that parameter - #2553

Open
maoxor wants to merge 1 commit into
prettier:mainfrom
maoxor:fix-comment-after-last-parameter
Open

maoxor wants to merge 1 commit into
prettier:mainfrom
maoxor:fix-comment-after-last-parameter

Conversation

@maoxor

@maoxor maoxor commented Oct 29, 2026

Copy link
Copy Markdown

Symfony and Doctrine document upcoming parameters with a comment after the last one:

public static function isValid(string $ulid /* , int $format = self::FORMAT_BASE_32 */): bool

When the signature is too long, the plugin breaks it and adds a trailing comma, which is fine:

public static function isValid(
    string $ulid /* , int $format = self::FORMAT_BASE_32 */,
): bool {

But formatting that output again moves the comment to the return type:

public static function isValid(
    string $ulid,
): /* , int $format = self::FORMAT_BASE_32 */ bool {

handleFunction attaches a comment located between the last argument and the body to the return type unless the next character is ). With the trailing comma, the next character is ,. It now skips a trailing comma before checking for ).

The new tests/comments/last-parameter.php has the comment with and without the trailing comma; before the change, the second form was printed after ):. yarn test (including the standalone build), AST_COMPARE=1 yarn test:node and yarn lint pass. Running the plugin twice on Symfony's Ulid.php, SymfonyStyle.php and TestHttpServer.php and Doctrine's ClassMetadata.php, NewObjectExpression.php and AbstractEntityPersister.php now gives the same output both times.

When the parameter list ends with a trailing comma, a comment between the last parameter and the comma was attached to the return type, so formatting the output again moved it after `):`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant