Skip to content

Commit

Permalink
Ignore key if scope cannot be evaluated
Browse files Browse the repository at this point in the history
- Fixes #441
  • Loading branch information
davidwessman authored and glebm committed Apr 5, 2022
1 parent fed0923 commit 9d2c825
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def convert_to_key_occurrences(send_node, method_name, location: send_node.loc)

key, default_arg = process_options(node: second_arg_node, key: key)

return if key.nil?

[
full_key(receiver: receiver, key: key, location: location, calling_method: method_name),
I18n::Tasks::Scanners::Results::Occurrence.from_range(
Expand Down Expand Up @@ -71,7 +73,7 @@ def process_options(node:, key:)
array_flatten: true,
array_reject_blank: true
)
return [key, nil] if scope.nil? && scope_node.type != :nil
return nil if scope.nil? && scope_node.type != :nil

key = [scope, key].join('.') unless scope == ''
end
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/used_keys/a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ def self.whot
I18n.t('activerecord.attributes.absolute.attribute')
translate('activerecord.attributes.absolute.attribute')
end

SCOPE_CONSTANT = 'path.in.translation.file'.freeze
def issue441
t('ignore_a', scope: SCOPE_CONSTANT)
t('ignore_b', scope: SCOPE_CONSTANT)
end
end

0 comments on commit 9d2c825

Please sign in to comment.