Skip to content
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

AstMatcher: Fixes typo for array scopes #445

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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