I'm looking for advice on how to properly format YAML files to improve their readability, especially for complex structures like OpenAPI files. I'm interested in finding a linter that can help with formatting, but many of them strip out empty lines, which makes it harder to follow deeply nested elements. Any recommendations?
3 Answers
Another approach is to run a script that parses and then rewrites your YAML files, maintaining the original format but ensuring consistency across your files. This method also helps catch any syntax issues along the way, while letting you check for any manual edits that might stray from your preferred format.
Have you considered using Prettier? It specifically keeps empty lines intact, which can really help with readability—especially for nested YAML files.
You could make your YAML more manageable by avoiding deep nesting wherever possible. Consider using references to simplify the structure. Also, a language server and linter can definitely aid in formatting. Redocly offers a CLI that includes a linter specifically for OpenAPI files—check it out!

That sounds like a smart strategy! Automating the formatting can save a lot of headaches down the road.