Skip to content

Commit

Permalink
Revert literal change (#410)
Browse files Browse the repository at this point in the history
Revert #405 #397
  • Loading branch information
otoyo authored Dec 23, 2021
1 parent 2552cdb commit be6e9c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 71 deletions.
8 changes: 3 additions & 5 deletions lib/i18n/tasks/scanners/ruby_key_literals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

module I18n::Tasks::Scanners
module RubyKeyLiterals
# NOTE
# "#{double_quoted["hash_pattern"]}" | "#{double_quoted_pattern}" | 'single_quoted_pattern' | :symbol_pattern
LITERAL_RE = /:?"[^\[]+\["[^"]+"\].+"|:?".+?"|:?'.+?'|:\w+/.freeze
LITERAL_RE = /:?".+?"|:?'.+?'|:\w+/.freeze

# Match literals:
# * String: '', "#{}", "#{hash["key"]}"
# * String: '', "#{}"
# * Symbol: :sym, :'', :"#{}"
def literal_re
LITERAL_RE
Expand All @@ -22,7 +20,7 @@ def strip_literal(literal)
literal
end

VALID_KEY_CHARS = /(?:[[:word:]]|[-.?!:;À-ž\/'"\[\]])/.freeze
VALID_KEY_CHARS = /(?:[[:word:]]|[-.?!:;À-ž\/])/.freeze
VALID_KEY_RE = /^#{VALID_KEY_CHARS}+$/.freeze

def valid_key?(key)
Expand Down
68 changes: 2 additions & 66 deletions spec/scanners/ruby_key_literals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,9 @@
Object.new.extend I18n::Tasks::Scanners::RubyKeyLiterals
end

describe '#literal_re' do
subject do
/(#{scanner.literal_re})/x =~ key
Regexp.last_match(1)
end

context 'string' do
context 'single quoted' do
let(:key) { %('some_key') }
it { is_expected.to eq(key) }
end

context 'double quoted' do
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

context 'symbol' do
context 'regular literal' do
let(:key) { %(:some_key) }
it { is_expected.to eq(key) }
end

context 'single quoted' do
let(:key) { %(:'some_key') }
it { is_expected.to eq(key) }
end

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

describe '#valid_key?' do
subject { scanner }

context 'slash in key' do
let(:key) { 'category/product' }
it { is_expected.to be_valid_key(key) }
end

context 'hash in key' do
let(:key) { 'category/product' }
let(:key) { 'some_hash["some_key"]' }
it { is_expected.to be_valid_key(key) }
it 'allows forward slash in key' do
expect(scanner).to be_valid_key('category/product')
end
end
end

0 comments on commit be6e9c9

Please sign in to comment.