Prettier: Multiple comments on top of if statement get separated

Created on 25 Oct 2017  路  1Comment  路  Source: prettier/prettier

When adding explanatory comments after Istanbul comments, prettier moves them around into a basically unformatted state.

Prettier 1.7.4
Playground link

Input:

  const x = 0;

  /* istanbul ignore if */ // debug case currently not triggered
  if (true) {
    x;
  }

Output:

const x = 0; // debug case currently not triggered

/* istanbul ignore if */ if (true) {
  x;
}

Expected behavior:

I would expect the following output to remain unchanged with regards to the comments:

  const x = 0;

  /* istanbul ignore if */ // debug case currently not triggered
  if (true) {
    x;
  }

I would expect the comments to stick to the if, where they must be for Istanbul to pick them up

comments javascript bug

Most helpful comment

You can move the line comment above the block comment as a workaround.

Prettier 1.7.4
Playground link

Input:

  const x = 0;

  // debug case currently not triggered
  /* istanbul ignore if */
  if (true) {
    x;
  }

Output:

const x = 0;

// debug case currently not triggered
/* istanbul ignore if */
if (true) {
  x;
}

>All comments

You can move the line comment above the block comment as a workaround.

Prettier 1.7.4
Playground link

Input:

  const x = 0;

  // debug case currently not triggered
  /* istanbul ignore if */
  if (true) {
    x;
  }

Output:

const x = 0;

// debug case currently not triggered
/* istanbul ignore if */
if (true) {
  x;
}

Was this page helpful?
0 / 5 - 0 ratings