Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor formatting adjustments #81

Merged
merged 1 commit into from
Apr 25, 2024
Merged

Refactor formatting adjustments #81

merged 1 commit into from
Apr 25, 2024

Conversation

sethvargo
Copy link
Owner

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

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
@sethvargo sethvargo mentioned this pull request Apr 19, 2024
1 task
@sethvargo sethvargo merged commit d57cc1a into main Apr 25, 2024
1 check passed
@sethvargo sethvargo deleted the sethvargo/multline branch April 25, 2024 19:13
@dcreey
Copy link
Collaborator

dcreey commented May 9, 2024

Sick. This makes a lot more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ratchet update exit with errors
2 participants