From affe3c0ccf14029d6bca5e320f4dac1cd8769a5d Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 10:48:05 +0100 Subject: [PATCH 1/6] Unify rubocop version specifications Specifying the runtime version is enough. --- rubocop-i18n.gemspec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rubocop-i18n.gemspec b/rubocop-i18n.gemspec index f04074c..f5a221b 100644 --- a/rubocop-i18n.gemspec +++ b/rubocop-i18n.gemspec @@ -2,7 +2,6 @@ lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -rubocop_version = '~> 0.51' Gem::Specification.new do |spec| spec.name = 'rubocop-i18n' @@ -27,6 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '>= 12.3.3' spec.add_development_dependency 'rb-readline', '~> 0.5.5' spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'rubocop', rubocop_version - spec.add_runtime_dependency 'rubocop', rubocop_version + spec.add_runtime_dependency 'rubocop', '~> 0.51' end From c491001fabbbae4d4d07d47decde5ece504c110a Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 10:48:42 +0100 Subject: [PATCH 2/6] Bump RuboCop version --- rubocop-i18n.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop-i18n.gemspec b/rubocop-i18n.gemspec index f5a221b..717b100 100644 --- a/rubocop-i18n.gemspec +++ b/rubocop-i18n.gemspec @@ -26,5 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '>= 12.3.3' spec.add_development_dependency 'rb-readline', '~> 0.5.5' spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_runtime_dependency 'rubocop', '~> 0.51' + spec.add_runtime_dependency 'rubocop', '~> 1.0' end From 780100b730c66c749a7be4ea772d309f73a3b507 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 10:49:34 +0100 Subject: [PATCH 3/6] Regenerate TODO file --- .rubocop_todo.yml | 74 +++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0d1df23..a3bc6a4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,44 +1,50 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-06-12 15:16:26 -0700 using RuboCop version 0.57.2. +# on 2020-10-25 09:49:30 UTC using RuboCop version 1.0.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 6 +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'rubocop-i18n.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. Lint/InterpolationCheck: Exclude: - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' -# Offense count: 4 +# Offense count: 2 +# Configuration parameters: IgnoredMethods. Metrics/AbcSize: Max: 29 -# Offense count: 6 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: - Enabled: false - Max: 61 - # Offense count: 1 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Enabled: false - Max: 106 + Max: 108 -# Offense count: 3 +# Offense count: 5 +# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 8 # Offense count: 7 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. Metrics/MethodLength: Max: 25 -# Offense count: 2 -Metrics/PerceivedComplexity: - Max: 8 +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/rubocop-i18n.rb' # Offense count: 2 Style/Documentation: @@ -49,37 +55,37 @@ Style/Documentation: - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' # Offense count: 12 -# Configuration parameters: EnforcedStyle. +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' - - 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + EnforcedStyle: template -# Offense count: 3 +# Offense count: 2 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' -# Offense count: 10 +# Offense count: 6 # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - - 'lib/rubocop/rspec/cop_helper.rb' -# Offense count: 93 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 5 +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + - 'lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb' + +# Offense count: 50 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https -Metrics/LineLength: +Layout/LineLength: Max: 174 - -Naming/FileName: - Exclude: - - 'lib/rubocop-i18n.rb' From 53b5a34606ccaf5a35f1497dd57b688e4c1231b5 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 10:59:13 +0100 Subject: [PATCH 4/6] Fix load order issues --- spec/spec_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d73021..ca2533f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require 'bundler/setup' -require 'shared_functions' -require 'shared_examples' require 'rubocop/cop/i18n' require 'rubocop/rspec/cop_helper' +require 'shared_examples' +require 'shared_functions' RSpec.configure do |config| # These two settings work together to allow you to limit a spec run From 5e824a47a88732830a8b60e46697bbb0a2795c19 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 11:05:11 +0100 Subject: [PATCH 5/6] Fix cop namespaces in specs --- spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb b/spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb index 4e555df..ec7b27e 100644 --- a/spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb +++ b/spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb @@ -110,7 +110,7 @@ context 'when ignoring raised exceptions' do let(:config) do - RuboCop::Config.new('RailsI18n/DecorateString' => { 'IgnoreExceptions' => true }) + RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'IgnoreExceptions' => true }) end %w[fail raise].each do |type| @@ -122,7 +122,7 @@ context 'when configuring a different regex' do let(:config) do - RuboCop::Config.new('RailsI18n/DecorateString' => { 'Regexp' => '^test-test-test$' }) + RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'Regexp' => '^test-test-test$' }) end it_behaves_like 'a_no_cop_required', "not_t('A sentence.')" @@ -131,7 +131,7 @@ context 'when string type' do let(:config) do - RuboCop::Config.new('RailsI18n/DecorateString' => { 'EnforcedSentenceType' => type }) + RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'EnforcedSentenceType' => type }) end context 'is sentence' do From 30fd767d8ba9392911048664acbc497d53c84bf9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 25 Oct 2020 11:07:33 +0100 Subject: [PATCH 6/6] Update Cop names in documentation --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1b87850..e11da38 100644 --- a/README.md +++ b/README.md @@ -34,33 +34,33 @@ require: ... # You *must* choose GetText or Rails-i18n style checking # If you want GetText-style checking -GetText: +I18n/GetText: Enabled: true -RailsI18n: +I18n/RailsI18n: Enabled: false # If you want rails-i18n-style checking -RailsI18n: +I18n/RailsI18n: Enabled: true -GetText: +I18n/GetText: Enabled: false # If you want custom control of all the cops -GetText/DecorateString: +I18n/GetText/DecorateString: Enabled: false # Disable the autocorrect AutoCorrect: false -GetText/DecorateFunctionMessage: +I18n/GetText/DecorateFunctionMessage: Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: +I18n/GetText/DecorateStringFormattingUsingInterpolation: Enabled: false -GetText/DecorateStringFormattingUsingPercent: +I18n/GetText/DecorateStringFormattingUsingPercent: Enabled: false -RailsI18n/DecorateString: +I18n/RailsI18n/DecorateString: Enabled: false ``` ## Cops -### GetText/DecorateString +### I18n/GetText/DecorateString This cop is looks for strings that appear to be sentences but are not decorated. Sentences are determined by the STRING_REGEXP. @@ -90,7 +90,7 @@ _("Result is good.") "a string that doesn't start with a capital letter." ``` -### GetText/DecorateFunctionMessage +### I18n/GetText/DecorateFunctionMessage This cop looks for any raise or fail functions and checks that the user visible message is using gettext decoration with the _() function. This cop makes sure the message is decorated, as well as checking that the formatting of the message is compliant according to the follow rules. @@ -206,7 +206,7 @@ raise(someOtherFuntioncall(foo, "bar")) In this raise or fail function, the message does not contain any decoration at all and the message is not a simple string. It may make sense to convert the message to a simple string. eg [Simple decoration of a message](#Simple-decoration-of-a-message). Or ignore this raise or fail function following this [How to ignore rules in code](#How-to-ignore-rules-in-code) section. -### GetText/DecorateStringFormattingUsingInterpolation +### I18n/GetText/DecorateStringFormattingUsingInterpolation This cop looks for decorated gettext methods _() and checks that all strings contained within do not use string interpolation '#{}' @@ -233,7 +233,7 @@ puts _("a message with a #{'interpolation'}") puts _("a message that is %{type}") % { type: 'translatable' } ``` -### GetText/DecorateStringFormattingUsingPercent +### I18n/GetText/DecorateStringFormattingUsingPercent This cop looks for decorated gettext methods _() and checks that all strings contained within do not use sprintf formatting '%s' etc @@ -256,7 +256,7 @@ raise(_("Warning is %s") % ['bad']) raise(_("Warning is %{value}") % { value: 'bad' }) ``` -### RailsI18n/DecorateString +### I18n/RailsI18n/DecorateString This cop looks for decorated rails-i18n methods. @@ -280,7 +280,7 @@ raise(translate("Warning is %{value}") % { value: 'good' }) raise(I18n.t("Warning is %{value}") % { value: 'good' }) ``` -### RailsI18n/DecorateStringFormattingUsingInterpolation +### I18n/RailsI18n/DecorateStringFormattingUsingInterpolation This cop looks for decorated rails-i18n methods like `t()` and `translate()` and checks that all strings contained within do not use string interpolation '#{}' @@ -311,11 +311,11 @@ puts t("path.to.key.with.interpolation") It may be necessary to ignore a cop for a particular piece of code. We follow standard rubocop idioms. ``` ruby -raise("We don't want this translated.") # rubocop:disable GetText/DecorateString -raise("We don't want this translated.") # rubocop:disable RailsI18n/DecorateString -raise("We don't want this translated") # rubocop:disable GetText/DecorateFunctionMessage -raise(_("We don't want this translated #{crazy}") # rubocop:disable GetText/DecorateStringFormattingUsingInterpolation) -raise(_("We don't want this translated %s") % ['crazy'] # rubocop:disable GetText/DecorateStringFormattingUsingPercent) +raise("We don't want this translated.") # rubocop:disable I18n/GetText/DecorateString +raise("We don't want this translated.") # rubocop:disable I18n/RailsI18n/DecorateString +raise("We don't want this translated") # rubocop:disable I18n/GetText/DecorateFunctionMessage +raise(_("We don't want this translated #{crazy}") # rubocop:disable I18n/GetText/DecorateStringFormattingUsingInterpolation) +raise(_("We don't want this translated %s") % ['crazy'] # rubocop:disable I18n/GetText/DecorateStringFormattingUsingPercent) ``` ## Known Issues