Skip to content

Prism: Do not scan code inside ERB comments - #763

Merged
davidwessman merged 1 commit into
mainfrom
fix-erb-comment-prism
Oct 10, 2026
Merged

davidwessman merged 1 commit into
mainfrom
fix-erb-comment-prism

Conversation

@davidwessman

Copy link
Copy Markdown
Collaborator

The Prism ERB scanner parsed the body of <%# ... %> comments as Ruby, only turning i18n-tasks-use into a comment. Any commented-out code such as <%# User.human_attribute_name(:foo) %> or <%# t("key") %> was thus reported as a used key. Turn every line of an ERB comment into a Ruby comment so that only the i18n-tasks-use magic comments are picked up, matching the Parser-based scanner.

Fixes #746

Authored by @anyingiit but I messed up the branches, thank you!

The Prism ERB scanner parsed the body of `<%# ... %>` comments as Ruby,
only turning `i18n-tasks-use` into a comment. Any commented-out code such
as `<%# User.human_attribute_name(:foo) %>` or `<%# t("key") %>` was thus
reported as a used key. Turn every line of an ERB comment into a Ruby
comment so that only the `i18n-tasks-use` magic comments are picked up,
matching the Parser-based scanner.

Fixes #746

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation preserves magic comments and includes adequate regression coverage.

0 open findings

What changed in this PR

Prevents Prism from scanning executable Ruby inside ERB comments while retaining i18n-tasks-use hints.

Changes:

  • Converts every ERB-comment line into a Ruby comment before Prism parsing.
  • Adds single-line and multiline regression fixtures and assertions.
  • Documents the fix for issue #746.
File Description
lib/​i18n/​tasks/​scanners/​erb_ast_scanner.rb Comments out ERB comment bodies before parsing.
spec/​used_keys_erb_prism_spec.rb Verifies commented-out keys are excluded.
spec/​fixtures/​used_keys/​app/​views/​application/​comments.html.erb Adds regression scenarios.
CHANGES.md Records the behavior fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@davidwessman
davidwessman merged commit bcb77e6 into main Oct 10, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prism reports offenses in comments

3 participants