Skip to content

Inconsistent formatting logic of PropertySignature and ObjectProperty #18209

@Dunqing

Description

@Dunqing

Prettier pr-18186
Playground link

--parser typescript

Input:

type A = {
  property: // Comment
  B;

  property2: /* Comment */
  B
  
  property3: /* Comment */
  B
}

const A2 = {
  property: // Comment
  B,

  property2: /* Comment */
  B,
  
  property3: /* Comment */ B
}

Output:

type A = {
  property: B; // Comment

  property2 /* Comment */: B;

  property3 /* Comment */: B;
};

const A2 = {
  // Comment
  property: B,

  /* Comment */ property2: B,

  property3: /* Comment */ B,
};

Expected output:

type A = {
  property: // Comment
  B;
  
  property2 /* Comment */: B;

  property3: /* Comment */ B;
};

const A2 = {
  property: // Comment
  B,

  property2 /* Comment */: B,

  property3: /* Comment */ B,
};

// or 

type A = {
  property: B; // Comment
  
  property2 /* Comment */: B;

  property3: /* Comment */ B;
};

const A2 = {
  property: B, // Comment

  property2 /* Comment */: B,

  property3: /* Comment */ B,
};

Why?

#18110 made some changes in the comments for PropertySignature, which caused property2: /* Comment */ B to be formatted as property2 /* Comment */ : B. I think the comment should keep its original place, that is said it should be formatted as `property2: /* Comment */ B

The expected output maintains consistency and keeps the comment position as similar as before.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions