Skip to content

YAML: Node Anchor followed by a blank line: "Nested mappings are not allowed in compact mappings" #10510

@jdufresne

Description

@jdufresne

Prettier 2.2.1
Playground link

Input:

key1: &default

  subkey1: value1

key2:
  <<: *default

Output:

test.yml[error] test.yml: SyntaxError: Nested mappings are not allowed in compact mappings (1:7)
[error] > 1 | key1: &default
[error]     |       ^^^^^^^^
[error] > 2 | 
[error]     | ^
[error] > 3 |   subkey1: value1
[error]     | ^
[error] > 4 | 
[error]     | ^
[error]   5 | key2:
[error]   6 |   <<: *default
[error]   7 | 

Expected behavior:

No error. The file should be formatted.

Both Python and Ruby YAML libraries load this file with the expected results.

In my production code, the blank line exists there to separate a comment.

key1: &default

  # This key ...
  subkey1: value1

key2:
  <<: *default

Which actually results in a different error:

test.yml[error] test.yml: SyntaxError: All collection items must start at the same column (1:1)
[error] > 1 | key1: &default
[error]     | ^^^^^^^^^^^^^^
[error] > 2 | 
[error]     | ^
[error] > 3 |   # This key ...
[error]     | ^
[error] > 4 |   subkey1: value1
[error]     | ^
[error] > 5 | 
[error]     | ^
[error] > 6 | key2:
[error]     | ^
[error] > 7 |   <<: *default
[error]     | ^
[error] > 8 | 
[error]     | ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:yamlIssues affecting YAMLlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions