-
-
Notifications
You must be signed in to change notification settings - Fork 195
Description
Describe the bug
This is a follow up bug to: #713
While the previous bug and PR resolved issues with Parsing un-even indentation on comments, those indentations are not preserved. This is less than desirable if the goal is simply to edit a single field and preserve the rest of the files formatting.
The use-case here is modifying values.yaml
files of helm charts that are human maintained. So we should not reformat the file and simply desire to use AST to select a field and update the value.
To Reproduce
Adding the following to TestComment cases will produce a failing test:
{
name: "commented values.yaml with uneven indentation",
yaml: `
topLevelNode:
attribute: true
# comment about the next attribute
# someOptInFeature: true
allGoodSoFar: true
# until this breaks it
despair: true
`,
},
Expected behavior
When yaml with un-even comments are parsed and modified, the un-even comments should maintain existing indent level (unless that was otherwise modified by the user.
So input of:
allGoodSoFar: true
# until this breaks it
despair: true
Seeking to set despair
to false
should output:
allGoodSoFar: true
# until this breaks it
despair: false
And not:
allGoodSoFar: true
# until this breaks it
despair: false
Screenshots
N/A
Version Variables
- Go version: 1.24
- go-yaml's Version: 1.18.0
Additional context
Add any other context about the problem here.