Skip to content

Trailing comment after empty method signature moves before parentheses #18835

@Dunqing

Description

@Dunqing

Prettier 3.8.1
Playground link

--parser babel-ts

Input:

interface foo1 {
bar3/* foo */ (/* baz */) // bat
bar/* foo */ ? /* bar */ (/* baz */) /* bat */;
bar2/* foo */ (/* baz */) /* bat */
}
interface foo2 {
bar/* foo */ ? /* bar */ (bar: /* baz */ string): /* bat */ string;
}

class foo1 {
  bar() /* bat */;
}

class Test {
  foo (/* 2 */) /* 3 */;
}

Output:

class foo1 {
  bar /* bat */();
}

class Test {
  foo /* 3 */(/* 2 */);
}

Expected output:

Same as input

class foo1 {
  bar() /* bat */;
}

class Test {
  foo(/* 2 */) /* 3 */;
}

Why?

Should keep the comments in their original place rather than break the order and move them to an incorrect place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentslang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions