Comments breaks nested indentation
It seems that comments breaks nested indentations sometimes.
$ dyff version 255 ↵
dyff version 1.6.0
MWE
foo.yaml
one:
two:
bar.yaml
one:
two:
three:
#comment: comment
four: true
five: true
Expected output
$ dyff between foo.yaml bar.yaml
_ __ __
_| |_ _ / _|/ _| between foo.yaml
/ _' | | | | |_| |_ and bar.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned one difference
|___/
one.two
± type change from <nil> to map
- <nil>
+ three:
#comment: comment
four: true
five: true
Actual output
$ dyff between foo.yaml bar.yaml
_ __ __
_| |_ _ / _|/ _| between foo.yaml
/ _' | | | | |_| |_ and bar.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned one difference
|___/
one.two
± type change from <nil> to map
- <nil>
+ three:
#comment: comment
four: true
five: true
While I do sympathize with the developers here (I'm not one of the developers of dyff) given Golang's YAML parser is notoriously weird, still.....
[!NOTE] This really should be a higher-priority issue given the output is not equivalent to the input given and could lead to humans making mistakes.
Maybe the reporter should retitle this issue as "[BUG] The use of comments on the next line after the start of a map leads to INACCURATE output in dyff between and dyff yaml." I've also seen a similar inaccuracy with dyff yaml with this case which is shown in the next comment.
I think the YAML specification is pretty clear that comment lines should not affect the calculation of what level the subsequent lines are on and the comment lines should be ignored entirely like they are not there.
If you need to work around this, you can remove your YAML comments via sed
sed '/^[[:blank:]]*#/d' pjm-da-energy-market-override-values.yaml | dyff yaml -
or just take the sed output and redirect to a file before running through dyff, but it would be nice to see this fixed.
Here's a simple example of much the same thing happening with dyff yaml (running version 1.10.2):
foo.yaml
one:
# a comment here can be either indented or not
two: true
three: true
Now if you run dyff yaml foo.yaml it will result in showing malformed(?) or at least non-equivalent YAML:
---
one:
# comment here can be either indented or not
two: true
three: true
Maybe this is an 'off-by-one' error where the indention is applied to the wrong line?
It also may be a good idea to add to your unit tests feeding the output of dyff yaml back into the Golang YAML parser just to verify it parses correctly (and maybe double-check if the output is functionally identical to the input?) It may not catch everything but it would catch more issues like this.