Skip to content

Linter: Improve unextractable tags in erb-no-duplicate-branch-elements - #2033

Merged
marcoroth merged 1 commit into
mainfrom
erb-no-duplicate-branch-elements-fixability
Aug 5, 2026
Merged

marcoroth merged 1 commit into
mainfrom
erb-no-duplicate-branch-elements-fixability

Conversation

@marcoroth

@marcoroth marcoroth commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

This pull request updates erb-no-duplicate-branch-elements to stop reporting shared tags that cannot actually be extracted, and makes the linter CLI stop advertising those offenses as autocorrectable.

<% if foo %>
  <p class="mt-3 text-balance">
    Content
  </p>

  <%= link_to "Link", other_path %>
<% else %>
  <p class="mt-3 text-balance">
    Other content
  </p>

  <%= link_to "Other link", other_path %>
<% end %>

which produced two hints plus Fixable 2 offenses | 2 autocorrectable using --fix, while --fix left the file untouched.

When the content of a shared tag differs between branches, the only way to extract it is to wrap the whole conditional in that tag.

The rule reported the hint without checking that this rewrite was available. In the template above the <p> has a sibling link_to that has to stay inside the conditional, so wrapping would swallow the links too. The only remaining "fix" is to split the conditional into several, which duplicates the condition instead of the markup.

Resolves #1570

@github-actions github-actions Bot added documentation Improvements or additions to documentation linter @herb-tools/linter for HTML+ERB templates typescript TypeScript source across the javascript/ packages linter-rule Individual linter rules and their documentation labels Aug 5, 2026
@marcoroth
marcoroth marked this pull request as ready for review August 5, 2026 23:30
@marcoroth
marcoroth enabled auto-merge (squash) August 5, 2026 23:30
@marcoroth
marcoroth merged commit 9886b8a into main Aug 5, 2026
20 of 21 checks passed
@marcoroth
marcoroth deleted the erb-no-duplicate-branch-elements-fixability branch August 5, 2026 23:39
@natematykiewicz

Copy link
Copy Markdown
Contributor

Does this also resolve #1878?

@marcoroth

Copy link
Copy Markdown
Owner Author

@natematykiewicz looks like it does. On current main they are not reported anymore: Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation linter @herb-tools/linter for HTML+ERB templates linter-rule Individual linter rules and their documentation typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report from Herb Playground

2 participants