Skip to content

yamlfix disagrees with yamllint

fix: improve project upgrade migrations (!271 - merged) introduced yamlfix as a step to touch up YAML files after template expansion.

Unfortunately yamllint disagrees with the generated results. Examples:

Specifically, the disagreement is over a multi-line array:

$ yamllint -f parsable .
./.golangci.yaml:332:7: [error] wrong indentation: expected 18 but found 6 (indentation)
./.golangci.yaml:333:7: [error] wrong indentation: expected 18 but found 6 (indentation)

Original source:

    initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS"]

"Fixed" result:

    initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON",
      "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL",
      "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS"]

I think the trigger is that we're setting YAMLFIX_SEQUENCE_STYLE=keep_style, so yamlfix keeps the flow style and needs to wrap it due to YAMLFIX_LINE_LENGTH=120. This seems to be a not that well supported corner case for yamlfix. I think the quick and easy fix would be to remove the line length limitation from yamlfix.

IMHO the root issue is that we're using two separate tools. We could run yamlfix in merge requests pipelines and verify that they would not change the formatting (similar to how we do with gofmt). Then, we can disable yamllint's indentation check. I prefer "formatting" tools over "linting" tools since they typically give people an easy fix (run the tool). That said, I'm not sure the effort required is worth it for YAML files.