question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

YAML: long property names/keys get prefixed with question mark `?`, and colon `:` gets wrapped onto the next line

See original GitHub issue

Prettier 1.15.3 Playground link

--parser yaml

Input:

very_long_name_in_fact_it_is_longer_than_80_characters_123123123123123123123123123:
  foo: "bar"

Output:

? very_long_name_in_fact_it_is_longer_than_80_characters_123123123123123123123123123
: foo: "bar"

Expected behavior:

Doesn’t wrap the : to the second line, i.e. leaves the whole thing intact.

very_long_name_in_fact_it_is_longer_than_80_characters_123123123123123123123123123:
  foo: "bar"

This issue looks simple to fix, where would I look for the related code if I wanted to make a PR?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
pdaviescommented, May 13, 2021

I hit this bug and have fixed it - see PR just above. For anyone interested, there’s some real black magic going on which made this pretty hard to figure out, but which feels commensurate to the wolf in sheep’s clothing that is the YAML grammar.

The intention of the code was to:

  • look at whether the key should break
  • if it does, use explicit mapping syntax. The bug was that if a key is long enough that it wants to break, it will trigger this, whether or not it actually can break onto multiple lines
  • if not, use implicit (ie normal) syntax

This is all pretty edge case stuff - many people will never know that yaml mapping keys can be multiline entities like arrays or multiline strings!

The extra dose of confusion comes from the pointless-looking call to conditionalGroup. It turns out that conditionalGroup has the undocumented behaviour of forcing the printer into MODE_FLAT, which the yaml formatter extensively relies on to prevent various breaks from occurring. Sensible-looking attempts to rewrite the code can very easily result in tons of line breaks appearing out of nowhere!

4reactions
deltaideacommented, May 7, 2019

@nasht00 One lazy workaround that I’ve used for this is setting max line length to 999 for Yaml files. Fixes the issue immediately but doesn’t look great if you have long lists with commas - they might get inlined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to escape indicator characters (colon and hyphen) in YAML
A pipe preserves newlines, a gt-sign turns all the following lines into one long string. Share.
Read more >
YAML Ain't Markup Language (YAML™) revision 1.2.2
Mappings use a colon and space (“ : ”) to mark each key/value pair. Comments begin with an octothorpe (also called a “hash”,...
Read more >
ETSI TS 129 501 V17.5.0 (2022-05)
found in ETSI SR 000 314: "Intellectual Property Rights (IPRs); Essential, ... The question mark character is a delimiter, which terminates ...
Read more >
Expert Python Programming Third Edition
Anyway, this book takes into account the fact that not everyone needs to be fully aware of the latest Python features or officially...
Read more >
Cobbler Documentation - Read the Docs
Before getting started with Cobbler, you should have a good working ... no errors were reported, you are ready to move on to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found