Skip to content

Prism: Candidate keys and parser fixes#684

Merged
davidwessman merged 3 commits into
mainfrom
prism-model-name-on-non-class
Nov 24, 2025
Merged

Prism: Candidate keys and parser fixes#684
davidwessman merged 3 commits into
mainfrom
prism-model-name-on-non-class

Conversation

@davidwessman

Copy link
Copy Markdown
Collaborator
  • Adds separate used_keys_ruby_prism_spec, catching some errors
    in the used_tree layer after the parser.
  • Separates haml and slim specs into separate files.
  • Fixes visitor to skip calls to translate methods on non-I18n classes.
  • Removes candidate keys for views and mailers
  • Adds candidate keys for model_name.human and human_attribute_name.

@davidwessman davidwessman force-pushed the prism-model-name-on-non-class branch 6 times, most recently from 623b51a to 92ad3a1 Compare November 23, 2025 08:38
@davidwessman davidwessman force-pushed the prism-model-name-on-non-class branch from a608416 to 6cd927d Compare November 23, 2025 10:09
- Adds separate used_keys_ruby_prism_spec, catching some errors
  in the used_tree layer after the parser.
- Separates haml and slim specs into separate files.
- Fixes visitor to skip calls to translate methods on non-I18n classes.
- Removes candidate keys for views and mailers
- Adds candidate keys for model_name.human and human_attribute_name.
@davidwessman davidwessman force-pushed the prism-model-name-on-non-class branch from 6cd927d to aed38d5 Compare November 23, 2025 10:14

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.

Pull request overview

This PR enhances the Prism-based translation scanner by fixing parser bugs, improving test organization, and adding candidate key support for Rails model methods. It ensures that only I18n module translation calls are processed, separates test specs by template type for better organization, and extends candidate key functionality to ActiveRecord model humanization methods while restricting them to controllers only.

  • Fixes Prism visitor to skip translate calls on non-I18n receivers (e.g., Service.translate(:key))
  • Adds candidate keys for model_name.human and human_attribute_name ActiveRecord methods
  • Restricts candidate keys generation to controllers only (removes from views and mailers)
  • Separates HAML and Slim specs into dedicated test files
  • Adds comprehensive Ruby Prism spec file to catch parser layer errors

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/used_keys_slim_spec.rb Removes HAML tests, keeping only Slim-specific tests; renames spec to "UsedKeysSlim"
spec/used_keys_haml_spec.rb New file containing HAML-specific tests moved from Slim spec
spec/used_keys_ruby_prism_spec.rb New comprehensive spec testing Ruby Prism parser with fixtures, including model method tests
spec/used_keys_erb_prism_spec.rb Updates test expectations to include candidate_keys for all occurrences
spec/support/keys_and_occurrences.rb Adds candidate_keys parameter to test helper methods
spec/prism_scanner_spec.rb Adds ::I18n.t test case and candidate_keys expectations for model methods
lib/i18n/tasks/scanners/ruby_scanner.rb Adds File.expand_path for JRuby compatibility in prism_parse_file
lib/i18n/tasks/scanners/prism_scanners/visitor.rb Adds receiver check to skip non-I18n translate calls; adds candidate_keys to model methods
lib/i18n/tasks/scanners/prism_scanners/nodes.rb Implements support_candidate_keys? method hierarchy; updates full_key logic for candidate_keys
lib/i18n/tasks/scanners/occurrence_from_position.rb Adds candidate_keys parameter to occurrence_from_position method
lib/i18n/tasks/scanners/erb_ast_scanner.rb Passes through candidate_keys when creating occurrences from ERB code and comments
CHANGES.md Documents fixes for non-I18n receiver processing, candidate keys for model methods, and used_tree integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/i18n/tasks/scanners/prism_scanners/visitor.rb Outdated
@davidwessman davidwessman merged commit 6b67f06 into main Nov 24, 2025
8 checks passed
@davidwessman davidwessman deleted the prism-model-name-on-non-class branch November 26, 2025 06:08
bart-westenenk-bex pushed a commit to bookingexperts/i18n-tasks that referenced this pull request Dec 10, 2025
- Adds separate used_keys_ruby_prism_spec, catching some errors
  in the used_tree layer after the parser.
- Separates haml and slim specs into separate files.
- Fixes visitor to skip calls to translate methods on non-I18n classes.
- Removes candidate keys for views and mailers
- Adds candidate keys for model_name.human and human_attribute_name.
bart-westenenk-bex pushed a commit to bookingexperts/i18n-tasks that referenced this pull request Dec 10, 2025
- Adds separate used_keys_ruby_prism_spec, catching some errors
  in the used_tree layer after the parser.
- Separates haml and slim specs into separate files.
- Fixes visitor to skip calls to translate methods on non-I18n classes.
- Removes candidate keys for views and mailers
- Adds candidate keys for model_name.human and human_attribute_name.
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.

3 participants