Skip to content

Commit

Permalink
AST scanner: support nested calls
Browse files Browse the repository at this point in the history
Original discovery and fix was made by @cantin:
kudelabs@9e8f4cc
  • Loading branch information
glebm committed May 2, 2017
1 parent ab80a26 commit c61f4e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/i18n/tasks/scanners/ruby_ast_call_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def on_send(send_node)
# use `any?` because `include?` checks type equality, but the receiver is a Parser::AST::Node != AST::Node.
if valid_receivers && valid_receivers.any? { |r| r == receiver }
@callback.call(send_node, @method_name)
else
handler_missing send_node
end
# always invoke handler_missing to get nested translations in children
handler_missing send_node
nil
end

Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def show()

# only `t()` calls can use relative keys and not `I18n.t()` calls.
I18n.t('.not_relative')

# Nested calls in ruby files should be reported
I18n.t('nested.parent.rb', x: I18n.t('nested.child.rb'))
end

def update
Expand Down
2 changes: 2 additions & 0 deletions spec/i18n_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
scope.key_in_erb
scope.relative.index.title
reference-missing-target.a
nested.parent.rb
nested.child.rb
] + ['⮕ missing_target']
end
let :expected_missing_keys_diff do
Expand Down

0 comments on commit c61f4e0

Please sign in to comment.