-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds experimental ErbAstScanner #416
Conversation
Could probably make another go at this by using https://github.com/Shopify/better-html or parts of https://github.com/Shopify/erb-lint. |
Absolutely, anything that replaces the current regexp parser is an improvement! |
Cool 😊 it passes the test suite locally as is. But maybe it needs to be added as an opt-in. I was also thinking if we could restructure the AST-matching to allow adding custom matchers like support for Rails model_name.human and human_attribute_name |
It can be the default (assuming comments and file positions are implemented), and we'll bump the minor version number.
Yeah, I'm sure that'd be helpful for lots of folks. |
I will try to think if I can figure out the file positions, must look through the Shopify-gems if they have any ideas. Would it be okay to only support comments that are in ERB-tags? <!-- i18n-tasks-use t('activerecord.models.company') --> <!-- this will be ignored -->
<% # i18n-tasks-use t('activerecord.models.company') %> <!-- this will be a magic comment -->
<h1><%= Company.model_name.human %></h1> |
Yes, this is how it is currently as well
|
24f2059
to
50cc09b
Compare
50cc09b
to
eba134a
Compare
@parser.reset | ||
associated_node = comment_to_node[comment] | ||
@call_finder.collect_calls( | ||
@parser.parse(make_buffer(path, comment.text.sub(MAGIC_COMMENT_PREFIX, '').split(/\s+(?=t)/).join('; '))) | ||
) do |send_node, _method_name| | ||
# method_name is not available at this stage | ||
send_node_to_key_occurrence(send_node, nil, location: associated_node || comment.location) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could replace the parsing here with the LocalRubyParser
I needed in the erb parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep sounds good 👍
@glebm I think it works now 👀 |
Clean and easy-to-read code with tests, amazing contribution 👍 |
Glad to hear 🙂 I will start to tinker with configurable AST-call-finders to add support for |
Create a basic AST for all dynamic and code calls in ERB based on theTemple::ERB::Parser and convert results to Parser::AST::Nodes to be
able to reuse a lot of RubyAstScanner.
It does not handle magic comments (maybe it would make sense to dothem with regex instead?
It will not get the correct position or line position, only rownumber.
Adds an AST-based parser using https://github.com/Shopify/better-html
@glebm Do you think something like this would be useful? I have seen it mentioned a few times in issues and such.