yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Make yamlfix more robust and prevent errors / mangling files by checking the generated output against a yaml-parser

Open marcules opened this issue 3 years ago • 1 comments

Description

yamlfix has a couple of fixers that operate on string replacement basis and there could be cases where those fixers mangle the yaml files or change them in a way that is not compliant.

Possible Solution

A general approach / solution could be to generate the newly fixed/linted yaml file into a temp file, parse the output with either ruyaml itself or another yaml parser, and if an error occurs don't modify the file. If no error occurs just move the modified file over the target file.

This would enable the user to be sure, that the file is 100% always parsable after yamlfix ran. This would also enable yamlfix to output a diff if the file was corrupted to warn the user of the reason why the file could not be fixed/linted.

Additional context

Related Issue

marcules avatar Dec 20 '22 16:12 marcules

Hi @marcules thanks for opening a new issue. I think it's a good idea, but I'm concerned about the performance penalty of doing all those operations, so I'd add a configuration key to let the users disable it.

lyz-code avatar Dec 21 '22 09:12 lyz-code