Skip to content

Inconsistent formatting logic of loop statements and conditional statements #18207

@Dunqing

Description

@Dunqing

Prettier 3.6.2
Playground link

--parser babel

Input:

while(true) // Comment
{}


while(true) /* Comment */
{}

while(true)
  /* Comment */
{}


for (let a = 0; a < 10; a ++) // Comment
{}


for (let a = 0; a < 10; a ++) /* Comment */
{}

for (let a = 0; a < 10; a ++) 
  /* Comment */
{}


if(true) // Comment
{}


if(true) /* Comment */
{}

if(true)
  /* Comment */
{}

Output:

while (true) {
  // Comment
}

while (true) {
  /* Comment */
}

while (true) {
  /* Comment */
}

for (
  let a = 0;
  a < 10;
  a++ // Comment
) {}

for (let a = 0; a < 10; a++ /* Comment */) {}

for (let a = 0; a < 10; a++) /* Comment */
{}

if (true) {
  // Comment
}

if (true) {
  /* Comment */
}

if (true) {
  /* Comment */
}

Expected output:

Hard to say what the expected output

Why?

Those are similar kinds of statements, so they should have the same formatting logic

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions