prettier icon indicating copy to clipboard operation
prettier copied to clipboard

`prettier-ignore` in YAML seems to apply to all following nodes instead of just the immediate next node

Open G-Rath opened this issue 3 years ago • 2 comments

Prettier 2.6.2 Playground link

# Options (if any):
--prose-wrap always

(happens regardless of --prose-wrap setting, but it's easier to see with it set to always)

Input:

# prettier-ignore
x:
  1
  2
  3
y: 
  1
  2
  3

Output:

# prettier-ignore
x:
  1
  2
  3
y: 
  1
  2
  3

Expected behavior:

# prettier-ignore
x:
  1
  2
  3
y: 1 2 3

Personally I think the expected behaviour makes more sense, but it could be the current behaviour is intended in which case I think the documentation could make it more obvious.

Currently it says:

# prettier-ignore should be placed on the line immediately above the ignored node:

which to me implies it'll only affect that node, rather than the nodes after it.

G-Rath avatar Jun 13 '22 20:06 G-Rath

Being the first line # prettier-ignore applies to the entire file in this case, which definitely is a bug.

thorn0 avatar Jun 15 '22 07:06 thorn0

The prettier ignores the entire map because the comment is parsed as the leading comment of the map.

I found a similar problem that in the following code, both x and y will be ignored. But I think ignoring x only makes more sense.

z:
  # prettier-ignore
  x:
    1
    2
    3
  y: 
    1
    2
    3

The same behaviour also appears on arrays.

fyc09 avatar Oct 13 '24 16:10 fyc09