YAML: Node Anchor followed by a blank line: "Nested mappings are not allowed in compact mappings"
See original GitHub issuePrettier 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] | ^
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
How to solve error nested mappings are not allowed in ...
The YAML you show is valid. We can't magically know what you did previously that yielded an error. To get an answer, edit...
Read more >YAML Ain't Markup Language (YAML™) revision 1.2.2
YAML supports two kinds of collection nodes: sequences and mappings. Mapping nodes are somewhat tricky because their keys are unordered and ...
Read more >YAML
Store the original node type when parsing documents. By default true . mapAsMap, boolean, When outputting JS, use Map rather than Object to...
Read more >Brief YAML reference — Camel 0.1.2 documentation
More convenient syntax tends to be more contextual or whitespace-sensitive. In the above document, you can see that indenting is enough to make...
Read more >YAML User Guide - Jekyll One
A single line break is folded into a single space, while empty lines are ... YAML directly supports both collections (mappings, sequences) and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jdufresne You aren’t going to like the resulting formatting though. As can be seen in the snapshots in the PR, the comment after the anchor doesn’t stay on its own line. That’ll be a separate issue.
Yah, it was what I thought.
yaml@1.10.2is out with this fixed.