Repository navigation
Prism: Do not scan code inside ERB comments - #763
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
🟢 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.
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Prism ERB scanner parsed the body of
<%# ... %>comments as Ruby, only turningi18n-tasks-useinto 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 thei18n-tasks-usemagic comments are picked up, matching the Parser-based scanner.Fixes #746
Authored by @anyingiit but I messed up the branches, thank you!