Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Allow "#{hash["key"]}" literal
Browse files Browse the repository at this point in the history
  • Loading branch information
otoyo committed Nov 20, 2021
1 parent 0627973 commit 52fa8e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/i18n/tasks/scanners/ruby_key_literals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module I18n::Tasks::Scanners
module RubyKeyLiterals
LITERAL_RE = /:?".+?"|:?'.+?'|:\w+/.freeze
LITERAL_RE = /:?"[\[]*(?:\[\s*")?.+(?:"\s*\])?"|:?'.+?'|:\w+/.freeze

# Match literals:
# * String: '', "#{}"
# * String: '', "#{}", "#{hash["key"]}"
# * Symbol: :sym, :'', :"#{}"
def literal_re
LITERAL_RE
Expand Down
23 changes: 21 additions & 2 deletions spec/scanners/ruby_key_literals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,27 @@
end

context 'double quoted' do
let(:key) { %q("#{some_key}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
context 'var' do
let(:key) { %q("#{some_key}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end

context 'hash' do
context 'double quoted key' do
let(:key) { %q("#{some_hash["some_key"]}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end

context 'single quoted key' do
let(:key) { %q("#{some_hash['some_key']}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end

context 'symbol key' do
let(:key) { %q("#{some_hash[:some_key]}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end
end
end
end

Expand Down

0 comments on commit 52fa8e8

Please sign in to comment.