Skip to content

Preserve end of line comments on the same line #12011

@amithm7

Description

@amithm7

Prettier 2.5.1
Playground link

--parser babel

Input:

if (a === 0) doSomething(); // comment A
else if (a === 1) doSomethingElse(); // comment B
else if (a === 2) doSomethingElse(); // comment C

Output:

if (a === 0) doSomething();
// comment A
else if (a === 1) doSomethingElse();
// comment B
else if (a === 2) doSomethingElse(); // comment C

Expected behavior:

Input is preserved as it is.

Comments at the end of line are put below the line with formatting, except the last statement.

Related issues:

This weird behavior around end of line comments have been reported before:

#807
#7155
#8708
#10250

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions