Skip to content

Formatter: Record each herb:disable anchor's output line while printing - #2786

Open
markokajzer wants to merge 1 commit into
marcoroth:mainfrom
markokajzer:herb-disable-record-output-lines
Open

markokajzer wants to merge 1 commit into
marcoroth:mainfrom
markokajzer:herb-disable-record-output-lines

Conversation

@markokajzer

@markokajzer markokajzer commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

alternative to #2785

records where each anchor's output ends while printing instead of searching the output for its text.

reproduction

<% foo %> <%# herb:disable erb-no-unused-expressions %>
<% foo %> <%# herb:disable erb-no-unused-expressions %>

before

<% foo %> <%# herb:disable erb-no-unused-expressions %> <%# herb:disable erb-no-unused-expressions %>
<% foo %>

after

unchanged input.

cause

findOutputLineForHerbDisable re-attached each collected comment to the first output line containing the anchor's search text (<% foo %>, <div, …), so identical anchors all resolved to the first match.

fix

  • mark the output line + column where each anchor (and its parent) ends after it's visited
    • output rendered inside capture() is resolved once the captured string is written
    • the text flow engine marks nodes after pushing the wrapped line they end on
    • multiline open tags also mark the tag name and attribute lines
  • splice each comment at the end of its anchor's physical line, in source order
  • drops the text search (findOutputLineForHerbDisable / getSearchableContentForNode)

also fixes

an earlier identical ERB tag the formatter normalizes no longer steals the comment

<%=foo%>
<%= foo %> <%# herb:disable some-rule %>

before:

<%= foo %> <%# herb:disable some-rule %>
<%= foo %>

after: unchanged input.

a disable after rewrapped text stays at the end of the text

<p>
  hello lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor
  hello incididunt ut labore et dolore magna aliqua <%# herb:disable some-rule %>
</p>

before:

<p>
  hello lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod <%# herb:disable some-rule %>
  tempor hello incididunt ut labore et dolore magna aliqua
</p>

after: unchanged input.

multiple disables on the same anchor keep their source order

<%= foo %> <%# herb:disable rule-a %> <%# herb:disable rule-b %>

before (flips back and forth on every format):

<%= foo %> <%# herb:disable rule-b %> <%# herb:disable rule-a %>

after: unchanged input.

not fixed

  • a disable on its own line with nothing before it in an element body still moves to the parent's closing tag line

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

This branch has not been deployed

No deployments
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