sethvargo / ratchet

A tool for securing CI/CD workflows with version pinning.
Apache License 2.0
769 stars 32 forks source link

Refactor formatting adjustments #81

Closed sethvargo closed 4 months ago

sethvargo commented 4 months ago

Instead of depending on a diff to restore newlines, this completely changes the algorithm to compare the input contents with the raw render YAML contents (before any mutations) to identify changes. We compute the places where newlines need to be injected, run Ratchet, and then insert those newlines back after modification. There are also now many more tests and a test harness that is more sustainable for adding tests and edge cases.

This also introduces an intentionally-undocumented environment variable that dumps debugging information about whitespace computations when set. This will help with issue debugging.

This results in a slight behavior change: YAML contents will have consistently-formatted indentation now, but all newline whitespace changes are preserved, including block scalars.

Fixes GH-80

dcreey commented 4 months ago

Sick. This makes a lot more sense.