Skip to content

Last indented list item inline comment is being moved to outer comment and combined with existing comment #11910

@pbelbin

Description

@pbelbin

Prettier 2.5.0
Playground link

--parser babel

Input:

// TypeScript interface
interface Thing1 {
	aaa: (
		| 'thing1' // Comment1
		| 'thing2' // Comment2
	)[]; // Final comment
}

Output:

// TypeScript interface
interface Thing1 {
  aaa: (
    | "thing1" // Comment1
    | "thing2"
  )[]; // Comment2 // Final comment
}

Expected behavior:

// TypeScript interface
interface Thing1 {
  aaa: (
    | "thing1" // Comment1
    | "thing2" // Comment2
  )[]; // Final comment
}

The placement of Comment2 in the sample output is the point of concern.

Curiously, using 'flow', 'babel', 'babel-flow' and 'typescript' parsers, the same incorrect output is obtained.

But: when using babel-ts as the parser, it seems to generate the expected output.

So, I'm thinking this is a bug in Prettier rather than in the parsers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentslang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs investigationIssues that need additional investigation, e.g. to understand whether the reported behavior is a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions