PrismScanner: Contextual parsing for Rails#565
Conversation
36d0316 to
fadc07d
Compare
|
We already have a Ruby parser dependency, consider reusing it rather than adding another one. |
Prism is a standard ruby gem and is included by default from Ruby 3.3 and can be installed from Ruby 3.0. I will do this experiment in Prism and then I can rewrite it to use the old parser. When parsing controllers I would like to return a key or a fallback, e.g. if there is a relative key in a method name I would like the key with either the method name included or with just the controller namespace. class EventsController < ApplicationController
def show
t(".relative")
end
endThen I would like it to first check for |
a325228 to
1fb6f4b
Compare
|
I don't mind dropping support for older rubies, but does Prism support JRuby?
Absolute keys are resolved by calling i18n-tasks/lib/i18n/tasks/scanners/relative_keys.rb Lines 7 to 12 in 2a9a9e0 Sounds like the code calling i18n-tasks/lib/i18n/tasks/data.rb Lines 11 to 13 in 2a9a9e0 |
|
Looks like Prism on JRuby is still a work-in-progress: http://blog.jruby.org/2024/02/jruby-prism-parser |
6946055 to
305b747
Compare
|
+1 for Prism! The speed gains rubocop is getting from using it are 👀 |
I think this means that JRuby are working on replacing their parser with Prism, for their compilation. |
5d7ae4e to
2018d84
Compare
ac7c37e to
6bcc609
Compare
87424f4 to
1ba8b45
Compare
Adds a scanner that supports: - `before_action` in controllers - translations in nested method calls - `model_name.human` - `human_attribute_name`
1ba8b45 to
e2dcf07
Compare
| %w[ | ||
| activerecord.attributes.event.title | ||
| activerecord.models.event.one | ||
| activerecord.models.event.other |
There was a problem hiding this comment.
Maybe we would like some different way to return a pluralized translation, e.g. that it would just return activerecord.models.event with some pluralized setting and then this can be included in the tree.
There was a problem hiding this comment.
Yeah, I think that would be necessary to support pluralized keys properly.
Can be done in a follow-up PR
|
@glebm Now I feel like I am ready for a review of this as a beta-feature. I am sorry for a large PR, please let me know if you have any suggestions for making it smaller and more reviewable. |
before_actionin controllersmodel_name.humanhuman_attribute_nameNote to reviewers
The scanner could replace all our calls to the
parsergem today and could in the future also replace our matchers.The harder part is to make it
extendable, should we allow the end user to implement their ownPrism::Visitorthat would support some new use case?I left the email subjects and ViewComponent for a smaller future PR, but I think this is a nice base to start testing it out on some real apps and evaluate if this is something we want to move towards.
TODO
Future features
defaultargument