From d8b98fa3bb674865f2aa891fdd163d54f3c87387 Mon Sep 17 00:00:00 2001 From: David Wessman Date: Tue, 7 May 2024 21:03:52 +0200 Subject: [PATCH] Fixes rubocop offenses (#564) - rubocop -a - Also changes Github Actions strategy to avoid fail-fast --- .github/workflows/tests.yml | 9 +++++---- lib/i18n/tasks/key_pattern_matching.rb | 8 ++++---- lib/i18n/tasks/scanners/relative_keys.rb | 2 +- lib/i18n/tasks/scanners/ruby_ast_scanner.rb | 2 +- lib/i18n/tasks/translators/google_translator.rb | 2 +- spec/google_translate_spec.rb | 16 ++++++++-------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c8ec1013..67a0e75e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,8 +1,8 @@ on: push: - branches: [ main ] + branches: [main] pull_request: - types: [ opened, synchronize ] + types: [opened, synchronize] jobs: lint: runs-on: ubuntu-latest @@ -14,7 +14,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '2.6' + ruby-version: "2.6" bundler-cache: true - name: Set-up RuboCop Problem Matcher @@ -26,7 +26,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7', '2.6'] + ruby-version: ["3.3", "3.2", "3.1", "3.0", "2.7", "2.6"] + fail-fast: false env: CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} GOOGLE_TRANSLATE_API_KEY: ${{ secrets.GOOGLE_TRANSLATE_API_KEY }} diff --git a/lib/i18n/tasks/key_pattern_matching.rb b/lib/i18n/tasks/key_pattern_matching.rb index bc29bc14..03568a8b 100644 --- a/lib/i18n/tasks/key_pattern_matching.rb +++ b/lib/i18n/tasks/key_pattern_matching.rb @@ -31,10 +31,10 @@ def compile_key_pattern(key_pattern) def key_pattern_re_body(key_pattern) key_pattern - .gsub(/\./, '\.') - .gsub(/\*:/, '[^.]+?') - .gsub(/\*/, '.*') - .gsub(/:/, '(?<=^|\.)[^.]+?(?=\.|$)') + .gsub('.', '\.') + .gsub('*:', '[^.]+?') + .gsub('*', '.*') + .gsub(':', '(?<=^|\.)[^.]+?(?=\.|$)') .gsub(/\{(.*?)}/) { "(#{Regexp.last_match(1).strip.gsub(/\s*,\s*/, '|')})" } end end diff --git a/lib/i18n/tasks/scanners/relative_keys.rb b/lib/i18n/tasks/scanners/relative_keys.rb index 78b2323f..ef363cb4 100644 --- a/lib/i18n/tasks/scanners/relative_keys.rb +++ b/lib/i18n/tasks/scanners/relative_keys.rb @@ -61,7 +61,7 @@ def prefix(normalized_path, calling_method: nil) "#{file_key.sub(/_controller$/, '')}.#{calling_method}" else # Remove _ prefix from partials - file_key.gsub(/\._/, DOT) + file_key.gsub('._', DOT) end end end diff --git a/lib/i18n/tasks/scanners/ruby_ast_scanner.rb b/lib/i18n/tasks/scanners/ruby_ast_scanner.rb index 734cce99..61794703 100644 --- a/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +++ b/lib/i18n/tasks/scanners/ruby_ast_scanner.rb @@ -81,7 +81,7 @@ def comments_to_occurences(path, ast, comments) results = [] # method_name is not available at this stage - calls.each do |send_node, _method_name| + calls.each do |(send_node, _method_name)| @matchers.each do |matcher| result = matcher.convert_to_key_occurrences( send_node, diff --git a/lib/i18n/tasks/translators/google_translator.rb b/lib/i18n/tasks/translators/google_translator.rb index 10437390..5cc8f05a 100644 --- a/lib/i18n/tasks/translators/google_translator.rb +++ b/lib/i18n/tasks/translators/google_translator.rb @@ -23,7 +23,7 @@ def options_for_translate_values(from:, to:, **options) options.merge( api_key: api_key, from: from, - to: to, + to: to ) end diff --git a/spec/google_translate_spec.rb b/spec/google_translate_spec.rb index da801254..ab6ae61c 100644 --- a/spec/google_translate_spec.rb +++ b/spec/google_translate_spec.rb @@ -80,7 +80,7 @@ 'config/locales/zh-tw.yml' => '', 'config/locales/zh-hant.yml' => '', 'config/locales/zh-hk.yml' => '', - 'config/locales/es.yml' => '', + 'config/locales/es.yml' => '' ) end @@ -99,18 +99,18 @@ task.data[:en] = build_tree('en' => { 'common' => { 'a' => 'λ', 'horse' => 'horse' } }) # Loading translations seems to require at least one existing value. - %w(zh zh-cn zh-hans zh-tw zh-hant zh-hk).each do |locale| + %w[zh zh-cn zh-hans zh-tw zh-hant zh-hk].each do |locale| task.data[locale] = build_tree(locale => { 'common' => { 'a' => 'λ' } }) end run_cmd 'translate-missing' - expect(task.t('common.horse', 'zh' )).to eq("马") # Simplified Chinese - expect(task.t('common.horse', 'zh-cn' )).to eq("马") # Simplified Chinese - expect(task.t('common.horse', 'zh-hans')).to eq("马") # Simplified Chinese - expect(task.t('common.horse', 'zh-tw' )).to eq("馬") # Traditional Chinese - expect(task.t('common.horse', 'zh-hant')).to eq("馬") # Traditional Chinese - expect(task.t('common.horse', 'zh-hk' )).to eq("馬") # Traditional Chinese + expect(task.t('common.horse', 'zh')).to eq('马') # Simplified Chinese + expect(task.t('common.horse', 'zh-cn')).to eq('马') # Simplified Chinese + expect(task.t('common.horse', 'zh-hans')).to eq('马') # Simplified Chinese + expect(task.t('common.horse', 'zh-tw')).to eq('馬') # Traditional Chinese + expect(task.t('common.horse', 'zh-hant')).to eq('馬') # Traditional Chinese + expect(task.t('common.horse', 'zh-hk')).to eq('馬') # Traditional Chinese end end end