Skip to content

Linter: Improve erb-unsued-block-argument offense messages - #1992

Merged
marcoroth merged 2 commits into
mainfrom
erb-unsued-block-arg-message
Aug 4, 2026
Merged

marcoroth merged 2 commits into
mainfrom
erb-unsued-block-arg-message

Conversation

@marcoroth

@marcoroth marcoroth commented Aug 4, 2026 •

Copy link
Copy Markdown
Owner

Follow up on #1958 and #1968.

Every unused block argument that isn't an each_with_index index gets the same advice today: "Remove it, or prefix it with an underscore". This pull request makes that concrete where it can be, and stops giving it where it is wrong.

Show the tag to write

When every argument of the block is unused, the parameter list can go entirely, so the message now shows the tag the author already wrote, minus the |...|:

<% pages.each do |page| %>
  <div class="stories-progress-bar"></div>
<% end %>
- Block argument `page` is never used. Remove it, or prefix it with an underscore as `_page` to show it is intentionally unused.
+ Block argument `page` is never used. Remove it and write `<% pages.each do %>`, or prefix it with an underscore as `_page` to show it is intentionally unused.

This is not limited to each, and the tag is rewritten from the source, so whatever the block is called on is kept as it is.

The rewrite is skipped, and the message falls back to the plain Remove it, when the tag spans multiple lines, when the rewritten tag would be longer than 60 characters, or when an argument the rule does not report (&block, **options) would be left behind.

Stop suggesting a removal that rebinds the other arguments

A block destructures what it is yielded based on how many parameters it declares, so removing one argument out of several is not the same edit as removing all of them:

[[1, 2], [3, 4]].each { |a, b| } # a is 1, b is 2
[[1, 2], [3, 4]].each { |a| }    # a is [1, 2]

Following the old advice here would rebind key from the key to the whole pair, and the page would start rendering [:name, "Marco"]:

<% @pairs.each do |key, value| %>
  <%= key %>
<% end %>
- Block argument `value` is never used. Remove it, or prefix it with an underscore as `_value` to show it is intentionally unused.
+ Block argument `value` is never used. Prefix it with an underscore as `_value` to show it is intentionally unused.

So removal is only offered when every reported argument is unused. When some of them are still in use, the underscore is the only correct fix and the message says just that. The same applies to the element of an each_with_index whose index is used, and to an unused argument of a destructured |(key, value)|.

The each_with_index message from #1968 is unchanged for the shape it was written for. When the element is used and only the index is not, it still suggests each instead of each_with_index.

@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 4, 2026
@github-actions

github-actions Bot commented Aug 4, 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 d0fe805


✅ Preview deployment has been cleaned up.

@pkg-pr-new

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

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

commit: d0fe805

@marcoroth
marcoroth marked this pull request as ready for review August 4, 2026 12:58
@marcoroth
marcoroth merged commit 8836f09 into main Aug 4, 2026
22 checks passed
@marcoroth
marcoroth deleted the erb-unsued-block-arg-message branch August 4, 2026 13:17

This branch was successfully deployed

1 active deployment
herb-tools (Preview) — d0fe8054 Deployed Aug 4, 2026 by github-actions[bot]
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.

1 participant