Skip to content

Formatter: Preserve inline whitespace in ERB branches - #2015

Merged
marcoroth merged 3 commits into
mainfrom
formatter-preserve-whitespace-in-erb-branches
Aug 5, 2026
Merged

marcoroth merged 3 commits into
mainfrom
formatter-preserve-whitespace-in-erb-branches

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request fixes the formatter silently deleting whitespace between text and ERB tags when that text sits inside an else, elsif, when, in, rescue or ensure branch.

Found while adopting the formatter on RubyEvents in rubyevents/rubyevents#2013

Minimal reproduction:

<span><% if a %>A<% else %>B <%= d %><% end %></span>

Before

<span><% if a %>A<% else %>B<%= d %><% end %></span>

After

<span><% if a %>A<% else %>B <%= d %><% end %></span>

No nesting is required, any text node touching an ERB tag inside a branch loses its edge whitespace. The same input in the if branch was always formatted correctly, which is what made this hard to spot.

@github-actions github-actions Bot added formatter @herb-tools/formatter for HTML+ERB templates typescript TypeScript source across the javascript/ packages labels Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit d970900


✅ Preview deployment has been cleaned up.

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
npx https://pkg.pr.new/@herb-tools/formatter@2015
npx https://pkg.pr.new/@herb-tools/language-server@2015
npx https://pkg.pr.new/@herb-tools/linter@2015

commit: d970900

@marcoroth
marcoroth merged commit 26b1456 into main Aug 5, 2026
22 checks passed
@marcoroth
marcoroth deleted the formatter-preserve-whitespace-in-erb-branches branch August 5, 2026 12:48
marcoroth added a commit to rubyevents/rubyevents that referenced this pull request Aug 5, 2026

This branch was successfully deployed

1 active deployment
herb-tools (Preview) — d970900d Deployed Aug 5, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter @herb-tools/formatter for HTML+ERB templates typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant