fix(uncomment): preserve indentation and flush buffer on uncommented lines#179
Merged
dadav merged 1 commit intodadav:mainfrom Feb 6, 2026
Merged
fix(uncomment): preserve indentation and flush buffer on uncommented lines#179dadav merged 1 commit intodadav:mainfrom
dadav merged 1 commit intodadav:mainfrom
Conversation
…lines
Fix two bugs in RemoveCommentsFromYaml that caused invalid YAML output
when using the --uncomment flag with nested structures.
Bug 1: Indentation stripping
The commentYamlMapMatcher regex captured the entire prefix including
YAML indentation (e.g., " # " for a 4-space indented comment).
When stripping comments, line[codeIndention:] removed both the comment
marker AND the indentation, causing nested values to lose their
nesting level and appear at the wrong depth in the output.
Fix: Capture indentation separately from the comment marker and
preserve the leading whitespace when stripping comments.
Bug 2: Uncommented lines incorrectly buffered
When inCode was true (processing a commented YAML block), any
non-comment line was added to the buffer instead of the result.
This caused uncommented values following commented values within
the same structure to be incorrectly grouped with the commented
block, producing malformed YAML.
Fix: When encountering an uncommented line while inCode is true,
flush the buffer to result, reset inCode to false, and add the
uncommented line directly to result. This allows commented and
uncommented fields to appear in any order within a structure.
Before (broken):
struct:
# commentedField: value
uncommentedField: value # incorrectly buffered
After (fixed):
struct:
commentedField: value # uncommented correctly
uncommentedField: value # passed through correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #178
Fix two bugs in RemoveCommentsFromYaml that caused invalid YAML output when using the --uncomment flag with nested structures.
Bug 1: Indentation stripping
The commentYamlMapMatcher regex captured the entire prefix including
YAML indentation (e.g., " # " for a 4-space indented comment).
When stripping comments, line[codeIndention:] removed both the comment
marker AND the indentation, causing nested values to lose their
nesting level and appear at the wrong depth in the output.
Fix: Capture indentation separately from the comment marker and preserve the leading whitespace when stripping comments.
Bug 2: Uncommented lines incorrectly buffered
When inCode was true (processing a commented YAML block), any non-comment line was added to the buffer instead of the result. This caused uncommented values following commented values within the same structure to be incorrectly grouped with the commented block, producing malformed YAML.
Fix: When encountering an uncommented line while inCode is true, flush the buffer to result, reset inCode to false, and add the uncommented line directly to result. This allows commented and uncommented fields to appear in any order within a structure.
Before (broken):
struct:
# commentedField: value
uncommentedField: value # incorrectly buffered
After (fixed):
struct:
commentedField: value # uncommented correctly
uncommentedField: value # passed through correctly
(Full disclosure this was done with the help of AI, no offense taken if you don't want to accept this. It worked on my fork and so I thought I would at least offer it up. Thanks again for this project!)