Fix comment parsing on anchors and aliases#815
Fix comment parsing on anchors and aliases#815joshuapare wants to merge 3 commits intogoccy:masterfrom
Conversation
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #815 +/- ##
==========================================
- Coverage 80.48% 80.35% -0.13%
==========================================
Files 22 22
Lines 6845 6863 +18
==========================================
+ Hits 5509 5515 +6
- Misses 914 920 +6
- Partials 422 428 +6 🚀 New features to boost your workflow:
|
60f75bd to
0faf12c
Compare
goccy
left a comment
There was a problem hiding this comment.
Thank you for your contribution !!! I've commented
| }{ | ||
| {"$.root.anchor_value", []*yaml.Comment{yaml.LineComment(" anchor comment")}}, | ||
| {"$.root.alias_value", []*yaml.Comment{yaml.LineComment(" alias comment")}}, | ||
| {"$.root.alias_flow", []*yaml.Comment{yaml.LineComment(" alias flow comment")}}, |
There was a problem hiding this comment.
Please add the test cases for anchor_flow and anchor_map
There was a problem hiding this comment.
sorry for the wait! This actually found a bug, sequence anchor ending comments weren't getting picked up. it's fixed now 👍
There was a problem hiding this comment.
Pull request overview
This PR fixes two bugs that occurred when CommentToMap was enabled with comments present on alias lines. The first bug caused alias lookup to fail because it used the string representation (which included comments) instead of the token value. The second bug prevented comments on alias lines from being propagated to the AliasNode, causing CommentToMap to miss them.
- Fixed alias lookup to use token value instead of string representation
- Added comment propagation from alias name to alias node
- Added comprehensive test coverage for anchors and aliases with comments
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| decode.go | Fixed alias lookup to use GetToken().Value instead of String() to avoid including comments in the lookup key |
| parser/parser.go | Added comment propagation from alias name StringNode to AliasNode to ensure CommentToMap can extract alias comments |
| testdata/yaml_test.go | Added test case covering anchors and aliases with comments for scalar values, flow sequences, and flow maps |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes two bugs around alias parsing (discovered while fixing #608) that occurred when CommentToMap was enabled with comments present on alias lines:
Example: