ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

Redefine yaml formatting rules to match other tools

Open ssbarnea opened this issue 2 years ago • 0 comments

I came recently to my attention that some decisions that we made in the past regarding the formatting rules ansible-lint checks for on YAML files may be in conflict with other formatters or yaml dumpers.

Tools evaluated so far

  • prettier - A very popular code formatter, supporting multiple file format.
  • vccode-yaml - vscode extension for editing YAML files, which seems to be re-using prettier for formatting. I am not aware of any divergence between them but afaik, it does not need prettier to be installed to work.
  • ruamel.yaml - a python library that can also dump yaml and format it in various ways, we already use it for loading yaml with comments. One particular feature is that it can preserve comments, something that pyyaml cannot.

Identified conflicts

too few spaces before comment

That rule is originating from yamllint and we could easily just disable it in our custom defaults for yamllint, those that are used as long user does not create his own yamllint config.

Apparently all 3 tools mentioned above do use only one space before an inline comment. Thus I am considering change our settings to match those tools, and avoid conflicts. I seen it myself how annoying is to observe that your editor reformatting on save may produce changes that later are undone by project CI.

TBD

Feel free to report other tools or conflicts that you know.

ssbarnea avatar Jan 21 '22 10:01 ssbarnea