tq: Preserve YAML comments by reattaching them per path
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
Research direction
Start with how the tq command decodes YAML input through any and how the Node model holds it, since the proposal keeps comments outside that model. The issue depends on an OrderedMap that is not yet in place, so check that dependency first. Done means a tq -e ... --inplace edit keeps head, line and foot comments and scalar styles on paths that still exist, and the known limits are documented.
Written by the indexing model from the issue text.
Description
Problem
YAML is decoded through any, so comments, anchors and scalar styles are lost. Editing a config file with tq -e ... --inplace rewrites every line, which rules out the main use case yq covers.
Proposed solution
Keep this out of the core Node model and handle it in tq:
- Also decode the input into
yaml.Nodeand collectpath → {HeadComment, LineComment, FootComment, Style}. - Query/edit the tree as usual.
- When encoding the result to
yaml.Node, copy comments and scalar styles back onto nodes whose path still exists.
Depends on key order preservation (OrderedMap) to be useful.
Known limits, to be documented: comments can shift to a neighbour when array elements are inserted/removed; anchors/aliases stay expanded (out of scope for 1.0).
- Dominant language
- Go
- Stars
- 7
- Forks
- 2
- Avg merge
- 11h 12m
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mojatter/tree
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
query: Read null like jq in key steps, comparisons and contains()Possibly taken @mojatter claimed this 1 day ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mojatter/tree#152 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
documentation ready
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Needs Triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
solongate/agent-security#154 ·
Maintainers usually reply within 1 day
-
tree: RootStyle is applied twice to the root nodePossibly taken @PhotoDotPi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
charmbracelet/lipgloss#772 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Maintainers usually reply within 1 day