Skip to content
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

fix: line break format issue after refactor code #44

Merged
merged 1 commit into from Sep 12, 2022

Conversation

longkai
Copy link
Contributor

@longkai longkai commented Sep 11, 2022

I notice my PR for retaining line breaks got refactors. However the original indentLen func got removed. It's required. Things got complicated when yaml contains literal multi-line string. If the indent is fixed 2, when it comes to multi-level indent string the format result will be wrong. So the paddinger always return the max padding for each line.

This PR fixes the refactor regression issue and explicitly add a test case.

Copy link
Collaborator

@braydonk braydonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry I misunderstood the edge case that indentLen was solving for. Appreciate the added test case.

if strings.TrimSpace(txt) == "" { // line break or empty space line.
buf.WriteString(padding.String()) // prepend some padding incase literal multiline strings.
buf.WriteString(lineBreakPlaceholder)
buf.WriteString(newlineStr)
continue
}
buf.WriteString(txt)
buf.WriteByte('\n')
buf.WriteString(newlineStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice catch, I missed that. I'll have to add some crlf test cases some time soon.

@braydonk braydonk merged commit 9fffda5 into google:main Sep 12, 2022
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.

None yet

2 participants