Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deltaidea opened this issue Dec 6, 2018 · 14 comments

Comments

@deltaidea
Copy link

@deltaidea deltaidea commented Dec 6, 2018

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?

@deltaidea deltaidea changed the title YAML: long property names/keys get prefixed with question mark `?` and colon `:` gets wrapped onto the next line YAML: long property names/keys get prefixed with question mark `?`, and colon `:` gets wrapped onto the next line Dec 6, 2018
@j-f1
Copy link
Member

@j-f1 j-f1 commented Dec 6, 2018

The code for this should be in src/language-yaml/printer-yaml.js.

@byronluk
Copy link

@byronluk byronluk commented Dec 30, 2018

@deltaidea Are you working on this? I was wondering if I could fix this. Thanks!

@deltaidea
Copy link
Author

@deltaidea deltaidea commented Dec 31, 2018

Go ahead! I completely forgot about this issue. :D
Thank you!

@flurmbo
Copy link
Contributor

@flurmbo flurmbo commented Jan 9, 2019

Hey @byronluk are you still working on this?

@byronluk
Copy link

@byronluk byronluk commented Jan 10, 2019

You can take it. I spent some time looking into it but haven't came up with a solution.

concat([ifBreak("? "), group(align(2, key), { id: groupId })])
),
ifBreak(
concat([hardline, ": ", align(2, value)]),

This is what adds the "?" and ":" prefix if that helps.

@flurmbo
Copy link
Contributor

@flurmbo flurmbo commented Jan 12, 2019

I have also not been able to find a solution. In particular, the conditional group on line 434 and the ifBreak on 439 of printer-yaml.js seem to behave differently than as described in commands.md.

@leggsimon
Copy link

@leggsimon leggsimon commented Mar 30, 2019

I think this label should be changed to difficulty:hard personally. Trying to navigate this is not hugely easy.

@nasht00
Copy link

@nasht00 nasht00 commented May 7, 2019

We are currently having this issue, and it is breaking our YAML.

Some clarification questions:

  • Is the ? syntax that it generates a supported feature of yml? Or is it a prettier bug? I see the issue is flagged as "feature" and not "bug" so I'm wondering why it breaks our code (we use express-openapi).
  • What is the suggested workaround?
@evilebottnawi
Copy link
Member

@evilebottnawi evilebottnawi commented May 7, 2019

/cc @ikatyang i think it is bug, not feature, right?

@ikatyang
Copy link
Member

@ikatyang ikatyang commented May 7, 2019

? is the syntax for explicit mapping keys as described in the YAML spec.

@nasht00
Copy link

@nasht00 nasht00 commented May 7, 2019

? is the syntax for explicit mapping keys as described in the YAML spec.

Does it mean that the generated example is valid?

? very_long_name_in_fact_it_is_longer_than_80_characters_123123123123123123123123123
: foo: "bar"

The yaml documentation is hard to read...

@ikatyang
Copy link
Member

@ikatyang ikatyang commented May 7, 2019

Yes, it's valid. It seems the library you used only implemented part of the spec.

@deltaidea
Copy link
Author

@deltaidea deltaidea commented 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.

@soullivaneuh
Copy link

@soullivaneuh soullivaneuh commented Mar 20, 2020

@deltaidea Does not look to be a good option according to this: #3468 (comment)

It produce not wanted behavior on files part getting in-lined when I don't want to.

This is a quite stuck situation. Apart of totally remove prettier from my tools, I don't see any other workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.