Skip to content

Commit

Permalink
AstMatcher: Fixes typo for array scopes
Browse files Browse the repository at this point in the history
- Fixes #444 and adds tests for it.
  • Loading branch information
davidwessman authored and glebm committed Apr 6, 2022
1 parent 152d368 commit 5ccada4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/i18n/tasks/scanners/ast_matchers/base_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def extract_string(node, array_join_with: nil, array_flatten: false, array_rejec
# `nil` is returned when a dynamic value is encountered in strict mode. Propagate:
return nil if str.nil?
end
elsif !@scanner&.config[:strict] && %i[dsym dstr].include?(node.type)
elsif !@scanner.config[:strict] && %i[dsym dstr].include?(node.type)
node.children.map do |child|
if %i[sym str].include?(child.type)
child.children[0].to_s
Expand Down Expand Up @@ -77,7 +77,7 @@ def extract_array_as_string(node, array_join_with:, array_flatten: false, array_
extract_string child
else
# ignore dynamic argument in strict mode
return nil if config[:strict]
return nil if @scanner.config[:strict]

if %i[dsym dstr].include?(child.type) || (child.type == :array && array_flatten)
extract_string(child, array_join_with: array_join_with)
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/used_keys/a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def issue441
t('ignore_a', scope: SCOPE_CONSTANT)
t('ignore_b', scope: SCOPE_CONSTANT)
end

def issue444
t('ignore_array', scope: [:ignore, SCOPE_CONSTANT])
end
end
17 changes: 16 additions & 1 deletion spec/used_keys_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
RSpec.describe 'UsedKeysRuby' do
let!(:task) { I18n::Tasks::BaseTask.new }
around do |ex|
task.config[:search] = { paths: paths }
task.config[:search] = { paths: paths, strict: strict }
TestCodebase.in_test_app_dir(directory: 'spec/fixtures/used_keys') { ex.run }
end

let(:paths) {
%w[a.rb]
}

let(:strict) {
true
}

it '#used_keys - ruby' do
used_keys = task.used_tree
expect(used_keys.size).to eq(1)
Expand Down Expand Up @@ -68,4 +72,15 @@
)
)
end

describe 'strict = false' do
let(:strict) { false }

it '#used_keys - ruby' do
used_keys = task.used_tree
expect(used_keys.size).to eq(1)
leaves = used_keys.leaves.to_a
expect(leaves.size).to(eq(4))
end
end
end

0 comments on commit 5ccada4

Please sign in to comment.