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