Closed juanvalino closed 1 year ago
Seems that the problem is in the write_comment()
method of yaml_utils.py
file, but I don't have enough skills of ruamel.yaml
to bring you a fix.
Doing some debug seems that the code enters in this if
after and empty or flow element, and seems it shouldn't:
if (
pre
and not value.strip()
and not isinstance(
self.event,
(
ruamel.yaml.events.CollectionEndEvent,
ruamel.yaml.events.DocumentEndEvent,
ruamel.yaml.events.StreamEndEvent,
ruamel.yaml.events.MappingStartEvent,
),
)
):
# drop pure whitespace pre comments
# does not apply to End events since they consume one of the newlines.
value = ""
I think this issue belongs to the ansible-lint repository, not to yamllint.
I filled the issue in ansible-lint
repository: https://github.com/ansible/ansible-lint/issues/3871
Seems that fix mode incorrectly removes empty lines before comments following empty or flow elements. This leads to inconsistent results and to the modification of yaml files correctly formatted.
Suppose the following input yaml file:
After applying
ansible-lint --fix
we get the following result:Look how some empty lines before comments following empty or flow elements got removed.