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

Refactor the diagnostic renderer to avoid printing trailing whitespace #430

Merged
merged 21 commits into from
Feb 5, 2025

Conversation

mcy
Copy link
Member

@mcy mcy commented Jan 22, 2025

This PR refactors the renderer so that all writes go through a shared state type, to ensure fine control over whitespace and line endings. This is also an opportunity to somewhat better organize how values are passed between functions in the renderer.

@mcy mcy requested a review from jhump January 22, 2025 22:49
emcfarlane
emcfarlane previously approved these changes Jan 31, 2025
experimental/report/writer.go Outdated Show resolved Hide resolved
experimental/report/writer.go Outdated Show resolved Hide resolved
return len(data), nil
}

func (w *writer) WriteBytes(b byte, n int) {
Copy link
Member

Choose a reason for hiding this comment

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

I think passing b = '\n' breaks this thing. This is only ever called with a space. How about instead just name it WritePadding(n int) and hardcode the space?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think b = '\n' breaks as the same WriteString("\n\n\n") would append \n\n\n to the buffer, just looping over and checking for right padding between each newline.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, Josh is right. Plus, having it only print spaces means we can make it more efficient.

@emcfarlane emcfarlane dismissed their stale review January 31, 2025 15:50

Unbounded buffering

@mcy mcy requested review from emcfarlane and jhump January 31, 2025 18:50
@doriable doriable self-requested a review February 3, 2025 17:12
@mcy mcy requested a review from doriable February 3, 2025 20:30
@mcy mcy requested a review from doriable February 3, 2025 20:59
experimental/report/writer.go Show resolved Hide resolved
experimental/report/writer.go Outdated Show resolved Hide resolved
@mcy mcy requested review from doriable and emcfarlane February 4, 2025 19:44
@mcy mcy enabled auto-merge (squash) February 5, 2025 18:04
@mcy mcy merged commit a1712a8 into main Feb 5, 2025
8 checks passed
@mcy mcy deleted the mcy/diagnostic-spaces branch February 5, 2025 18:09
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.

4 participants