Skip to content

Linter: Don't flag case operands in erb-no-unused-literals - #1978

Merged
marcoroth merged 1 commit into
mainfrom
erb-no-unused-literals-case-conditions
Aug 3, 2026
Merged

marcoroth merged 1 commit into
mainfrom
erb-no-unused-literals-case-conditions

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request updates the LiteralCollector in erb-no-unused-literals to skip the comparison operands of case/when and case/in statements, which were being reported as unused literals.

LiteralCollector is a blocklist-based visitor. It overrides visitCallNode to skip arguments and stops traversal into every assignment node type plus visitReturnNode/visitBreakNode/visitNextNode, but it had no handling for WhenNode, InNode, CaseNode or CaseMatchNode.

The rule bug was always there, it just wasn't reachable before #1885, PrismVisitor never descended into node list fields, so when/in branch conditions never reached the collector. Once that was fixed, every literal condition started landing in literals.

<% case value
   when "a"
     result = 1
   end %>
a.html.erb:
  2:8  ✗ Avoid using silent ERB tags for literals. `"a"` is evaluated but never used or output. (erb-no-unused-literals)

"a" isn't unused, it's the operand value is compared against. The same applied to in patterns and to a literal case subject.

Follow up on #1885
Resolves #1972

@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 3, 2026
@marcoroth
marcoroth force-pushed the erb-no-unused-literals-case-conditions branch 3 times, most recently from ed647fb to 866adff Compare August 3, 2026 14:17
@github-actions github-actions Bot added the c C source for the core parser, lexer, and AST label Aug 3, 2026
@marcoroth
marcoroth force-pushed the erb-no-unused-literals-case-conditions branch from 866adff to 9d1e4ab Compare August 3, 2026 14:21
@marcoroth marcoroth removed documentation Improvements or additions to documentation c C source for the core parser, lexer, and AST labels Aug 3, 2026
@marcoroth
marcoroth marked this pull request as ready for review August 3, 2026 14:23
@github-actions

github-actions Bot commented Aug 3, 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 9d1e4ab


✅ Preview deployment has been cleaned up.

@pkg-pr-new

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

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

commit: 9d1e4ab

@marcoroth
marcoroth merged commit 9a58b3c into main Aug 3, 2026
22 checks passed
@marcoroth
marcoroth deleted the erb-no-unused-literals-case-conditions branch August 3, 2026 15:20

This branch was successfully deployed

1 active deployment
herb-tools (Preview) — 9d1e4abe Deployed Aug 3, 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.

Linter: erb-no-unused-literals false positives on case/when and case/in conditions

1 participant