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

Wrong front matter interpretation #147

Open
BnGx opened this issue Oct 25, 2023 · 1 comment
Open

Wrong front matter interpretation #147

BnGx opened this issue Oct 25, 2023 · 1 comment
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.

Comments

@BnGx
Copy link

BnGx commented Oct 25, 2023

Description

The yamlfmt program does not evaluate the frontmatter correctly when already present in the yaml file and the formatter configuration specifies include_document_start with true.

The problem is evident when there are particular comments such as the vim modelines before the frontmatter, if the latter is moved to line 1 the modeline is not evaluated correctly by the editors.

Steps to play

  • Create a .yamlfmt configuration file and set the include_document_start option to true in the section formatter;
  • Create a yaml file with a modeline on line 1, the front matter on line 2 and arbitrary content starting from line 3.
  • Run yamlfmt on the created yaml file.

Expected behavior

If the front matter is already present in the file and preceded by comments, it should not be moved to the first line of the file.

If it is not present you should insert it after modelines or after all the initial comments before the first valid yaml line.

Scripts

echo "# vim: ft=yaml" > myfile.yaml
echo "---" >> myfile.yaml
echo "# My comment" >> myfile.yaml
echo "mycontent: yes" >> myfile.yaml
echo "formatter: {include_document_start: true}" > .yamlfmt
yamlfmt myfile.yaml

Environment details

  • Operating system: Ubuntu 22.04
  • Yamlfmt version: 0.10.0
  • Shell used: bash
@BnGx BnGx changed the title Wrong document start interpretation Wrong front matter interpretation Oct 25, 2023
@braydonk braydonk added the yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix. label Oct 25, 2023
@braydonk
Copy link
Collaborator

This looks similar to #74. Similar to the other issues with the underlying yaml library, I'm not sure if I will be able to get to it anytime soon unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.
Projects
None yet
Development

No branches or pull requests

2 participants