From be6e9c9c9d1759916f1f4eab4ba8f9b2d800d174 Mon Sep 17 00:00:00 2001 From: Hiroki Toyokawa Date: Thu, 23 Dec 2021 11:09:09 +0900 Subject: [PATCH] Revert literal change (#410) Revert #405 #397 --- lib/i18n/tasks/scanners/ruby_key_literals.rb | 8 +-- spec/scanners/ruby_key_literals_spec.rb | 68 +------------------- 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/lib/i18n/tasks/scanners/ruby_key_literals.rb b/lib/i18n/tasks/scanners/ruby_key_literals.rb index f71a87fd..73863e1c 100644 --- a/lib/i18n/tasks/scanners/ruby_key_literals.rb +++ b/lib/i18n/tasks/scanners/ruby_key_literals.rb @@ -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 @@ -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) diff --git a/spec/scanners/ruby_key_literals_spec.rb b/spec/scanners/ruby_key_literals_spec.rb index 4479fbe8..a7342fdf 100644 --- a/spec/scanners/ruby_key_literals_spec.rb +++ b/spec/scanners/ruby_key_literals_spec.rb @@ -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