Skip to content

Linter: Improve erb-no-output-control-flow offense message - #2008

Merged
marcoroth merged 1 commit into
mainfrom
improve-erb-no-output-control-flow-message
Aug 5, 2026
Merged

marcoroth merged 1 commit into
mainfrom
improve-erb-no-output-control-flow-message

Conversation

@marcoroth

@marcoroth marcoroth commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

This pull request updates the offense message of erb-no-output-control-flow so that it names the keyword that was actually used and suggests the actual corrected tag, instead of a generic placeholder.

Previously the keyword came from a static node type to name mapping, which meant elsif was reported as if, since elsif is parsed as an ERBIfNode:

<% if condition? %>
  ...
<%= elsif another_condition? %>
  ...
<% end %>
Control flow statements like `if` should not be used with output tags. Use `<% if ... %>` instead.

The keyword and the suggested replacement are now both derived from the content of the reported tag, the same way the iteration block branch of this rule already builds its suggestion:

Control flow statements like `elsif` should not be used with output tags. Use `<% elsif another_condition? %>` instead.

@github-actions github-actions Bot added 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
@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 497f308


✅ 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@2008
npx https://pkg.pr.new/@herb-tools/language-server@2008
npx https://pkg.pr.new/@herb-tools/linter@2008

commit: 497f308

@marcoroth
marcoroth marked this pull request as ready for review August 5, 2026 08:44
@marcoroth
marcoroth merged commit e22b9a1 into main Aug 5, 2026
22 checks passed
@marcoroth
marcoroth deleted the improve-erb-no-output-control-flow-message branch August 5, 2026 08:44
marcoroth added a commit that referenced this pull request Aug 5, 2026
Follow up on #2008.

This pull request makes `erb-no-output-control-flow` autocorrectable.
Now that the offense message spells out the exact replacement, the rule
can also apply it. The fix is a single token mutation, `<%=` becomes
`<%`, which covers every shape the rule reports: `if`, `unless`,
`elsif`, `else`, `end` and iteration blocks.

```diff
- <%= if condition? %>
+ <% if condition? %>
    <p>Content</p>
- <%= elsif another_condition? %>
+ <% elsif another_condition? %>
    <p>Content</p>
- <%= end %>
+ <% end %>
```
marcoroth added a commit that referenced this pull request Aug 6, 2026
Similar to #2008, this pull request updates the offense message of
`erb-no-unused-expressions` so that it shows the actual ERB tag that was
reported and the actual tag it suggests, instead of the generic `<%= ...
%>` placeholder.

Previously the message named the expression on its own and always
pointed at a placeholder for the fix, which left it up to the reader to
assemble the suggestion themselves. Both halves of the message are now
built from the reported tag:

```html+erb
<!DoCTyPe <% hello world %> hello world this is inside the doctype>
```

```diff
- [error] Avoid unused expressions in silent ERB tags. `hello world` is evaluated but its return value is discarded. Use `<%= ... %>` to output the value or remove the expression. (erb-no-unused-expressions)
+ [error] Avoid unused expressions in silent ERB tags. `<% hello world %>` is evaluated but its return value is discarded. Use `<%= hello world %>` to output the value or remove the expression. (erb-no-unused-expressions)
```

This branch was successfully deployed

1 active deployment
herb-tools (Preview) — 497f3081 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

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