10000 Add PreserveCommentIndents to provide ability to preserve comments with odd indentation by mallardduck · Pull Request #749 · goccy/go-yaml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add PreserveCommentIndents to provide ability to preserve comments with odd indentation #749

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mallardduck
Copy link
@mallardduck mallardduck commented May 30, 2025

This PR solves: #747 (and is a follow up to #734)

It allows for the parser (and AST nodes) to pre configured to preserve the level of indentation that comments are found to be at. This helps to cover some additional use-cases that cannot be supported currently like the one I reported initially here: #713 (comment)

This is accomplished by adding a new mode that is used along side with ParseComments mode. Notably if the new mode is used alone it currently will not work.

I opted for a new mode because based on the report from #713 and fix in #734 it seems some users/use-cases desire comments Parsed but not preserved at same indent. It seems this functions as a minimal beautification step in that case.


Future Consideration

This does not cover, nor seek to attempt covering, other comment related indent concerns. For instance in-line comments may have odd spacing following the value that the comment is after. So something like:

		{
			name: "commented values.yaml with odd in-line indentation",
			yaml: `
topLevelNode:
  attribute: true          # comment about the current line's attribute
`,
		},

While it could be possible to preserve this spacing in some cases - i.e. to ensure the # outputs in the same column as it is found. This would be a risk as, in cases where the value length changes (grows) a collision could occur. So because that solution is quite a different issue than indent levels this has been intentionally excluded from this fix.


Before submitting your PR, please confirm the following.

  • Describe the purpose for which you created this PR.
  • Create test code that corresponds to the modification

@mallardduck mallardduck force-pushed the comment-indentation branch from bf20388 to 387b24a Compare May 30, 2025 05:54
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.98%. Comparing base (52dacb8) to head (387b24a).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #749   +/-   ##
=======================================
  Coverage   77.97%   77.98%           
=======================================
  Files          22       22           
  Lines        8108     8111    +3     
=======================================
+ Hits         6322     6325    +3     
  Misses       1370     1370           
  Partials      416      416           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants
0