From 976a8c85518733d3965d225357994d97c377e858 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 16:23:31 -0700 Subject: [PATCH 01/11] Restructure supported methods/decorators Prior to this commit we were duplicating the list of supported methods and decorators in each cop. This commit moves the list of methods and decorators out into the parent GetText class and adds a supported_decorator? method. --- lib/rubocop/cop/i18n/gettext.rb | 10 ++++++++++ .../cop/i18n/gettext/decorate_function_message.rb | 12 ++---------- ...decorate_string_formatting_using_interpolation.rb | 10 +--------- .../decorate_string_formatting_using_percent.rb | 9 +-------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lib/rubocop/cop/i18n/gettext.rb b/lib/rubocop/cop/i18n/gettext.rb index 8180ee8..026305e 100644 --- a/lib/rubocop/cop/i18n/gettext.rb +++ b/lib/rubocop/cop/i18n/gettext.rb @@ -4,6 +4,16 @@ module RuboCop module Cop module I18n module GetText + SUPPORTED_METHODS = ['raise', 'fail'] + SUPPORTED_DECORATORS = ['_', 'n_', 'N_'] + + def self.supported_method?(method_name) + SUPPORTED_METHODS.include?(method_name) + end + + def self.supported_decorator?(decorator_name) + SUPPORTED_DECORATORS.include?(decorator_name) + end end end end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb b/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb index 1a15d9c..f8caf25 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb @@ -3,12 +3,9 @@ module Cop module I18n module GetText class DecorateFunctionMessage < Cop - SUPPORTED_METHODS = ['raise', 'fail'] - SUPPORTED_DECORATORS = ['_', 'n_', 'N_'] - def on_send(node) method_name = node.loc.selector.source - return if !supported_method_name?(method_name) + return if !GetText.supported_method?(method_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && !already_decorated?(node) && (contains_string?(arg_nodes) || string_constant?(arg_nodes)) if string_constant?(arg_nodes) @@ -22,16 +19,11 @@ def on_send(node) end private - - def supported_method_name?(method_name) - SUPPORTED_METHODS.include?(method_name) - end - def already_decorated?(node, parent = nil) parent ||= node if node.respond_to?(:loc) && node.loc.respond_to?(:selector) - return true if SUPPORTED_DECORATORS.include?(node.loc.selector.source) + return true if GetText.supported_decorator?(node.loc.selector.source) end return false unless node.respond_to?(:children) diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb index e9748d1..0d5165c 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb @@ -20,12 +20,9 @@ module GetText # _("result is %{detail}" % {detail: message}) # class DecorateStringFormattingUsingInterpolation < Cop - - SUPPORTED_DECORATORS = ['_', 'n_', 'N_'] - def on_send(node) decorator_name = node.loc.selector.source - return if !supported_decorator_name?(decorator_name) + return if !GetText.supported_decorator?(decorator_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && contains_string_formatting_with_interpolation?(arg_nodes) message_section = arg_nodes[0] @@ -34,11 +31,6 @@ def on_send(node) end private - - def supported_decorator_name?(decorator_name) - SUPPORTED_DECORATORS.include?(decorator_name) - end - def string_contains_interpolation_format?(str) str.match(/\#{[^}]+}/) end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb index fe8d4de..70b3ec0 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb @@ -22,13 +22,11 @@ module GetText # _("result is %{detail}" % {detail: message}) # class DecorateStringFormattingUsingPercent < Cop - - SUPPORTED_DECORATORS = ['_', 'n_', 'N_'] SUPPORTED_FORMATS = %w[b B d i o u x X e E f g G a A c p s] def on_send(node) decorator_name = node.loc.selector.source - return if !supported_decorator_name?(decorator_name) + return if !GetText.supported_decorator?(decorator_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && contains_string_with_percent_format?(arg_nodes) message_section = arg_nodes[0] @@ -37,11 +35,6 @@ def on_send(node) end private - - def supported_decorator_name?(decorator_name) - SUPPORTED_DECORATORS.include?(decorator_name) - end - def string_contains_percent_format?(str) SUPPORTED_FORMATS.any? { |format| str.match(/%([-+])?[0-9]*(\.[0-9]*)?#{format}/) } end From 53f8b53d1b9ea8b27f5fb7ded538e7e502f241d8 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 16:38:36 -0700 Subject: [PATCH 02/11] Add additional decorators/update specs This commit adds additional decorators that are supported by various Ruby gettext libraries as well as spec updates to test them. --- lib/rubocop/cop/i18n/gettext.rb | 32 ++++++++++++++++--- .../gettext/decorate_function_message_spec.rb | 17 +++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/rubocop/cop/i18n/gettext.rb b/lib/rubocop/cop/i18n/gettext.rb index 026305e..badad36 100644 --- a/lib/rubocop/cop/i18n/gettext.rb +++ b/lib/rubocop/cop/i18n/gettext.rb @@ -4,15 +4,39 @@ module RuboCop module Cop module I18n module GetText - SUPPORTED_METHODS = ['raise', 'fail'] - SUPPORTED_DECORATORS = ['_', 'n_', 'N_'] + def self.SUPPORTED_METHODS + ['raise', 'fail'] + end + # Supports decorators from + # * mutoh/gettext https://github.com/mutoh/gettext/blob/master/lib/gettext.rb + # * grosser/fast_gettext https://github.com/grosser/fast_gettext/blob/master/lib/fast_gettext/translation.rb + def self.SUPPORTED_DECORATORS + [ + '_', + 'n_', + 'np_', + 'ns_', + 'N_', + 'Nn_', + 'D_', + 'Dn_', + 'Ds_', + 'Dns_', + 'd_', + 'dn_', + 'ds_', + 'dns_', + 'p_', + 's_', + ] + end def self.supported_method?(method_name) - SUPPORTED_METHODS.include?(method_name) + self.SUPPORTED_METHODS.include?(method_name) end def self.supported_decorator?(decorator_name) - SUPPORTED_DECORATORS.include?(decorator_name) + self.SUPPORTED_DECORATORS.include?(decorator_name) end end end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb index 85f15e5..fb82ccd 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb @@ -8,8 +8,7 @@ investigate(cop, source) } - functions = ['fail', 'raise'] - functions.each do |function| + RuboCop::Cop::I18n::GetText.SUPPORTED_METHODS.each do |function| context "#{function} with undecorated double-quote message" do it_behaves_like 'a_detecting_cop', "#{function}(\"a string\")", function, 'message string should be decorated' it_behaves_like 'a_fixing_cop', "#{function}(\"a string\")", "#{function}(_(\"a string\"))", function @@ -47,11 +46,13 @@ expect(cop.offenses.size).to eq(0) end end - context "#{function} with the n_ decorator" do - it_behaves_like 'a_no_cop_required', "#{function}(n_(\"a string\"))", function - it_behaves_like 'a_no_cop_required', "#{function}(n_('a string'))", function - it_behaves_like 'a_no_cop_required', "#{function}(CONSTANT, n_('a string'))", function - it_behaves_like 'a_no_cop_required', "#{function}(n_(\"a string %{value0}\")) % { value0: var, }", function + RuboCop::Cop::I18n::GetText.SUPPORTED_DECORATORS.each do |decorator| + context "#{function} with the #{decorator} decorator" do + it_behaves_like 'a_no_cop_required', "#{function}(#{decorator}(\"a string\"))", function + it_behaves_like 'a_no_cop_required', "#{function}(#{decorator}('a string'))", function + it_behaves_like 'a_no_cop_required', "#{function}(CONSTANT, #{decorator}('a string'))", function + it_behaves_like 'a_no_cop_required', "#{function}(#{decorator}(\"a string %{value0}\")) % { value0: var, }", function + end end end context "real life examples," do @@ -69,7 +70,7 @@ end it 'autocorrects', broken: true do - corrected = autocorrect_source( "raise(Puppet::ParseError, \"mysql_password(): Wrong number of arguments \" \\ \"given (\#{args.size} for 1)\")" ) + corrected = autocorrect_source( "raise(Puppet::ParseError, \"mysql_password(): Wrong number of arguments \" \\ \"given (\#{args.size} for 1)\")" ) expect(corrected).to eq("raise(Puppet::ParseError, _(\"a string %{value0}\") % { value0: var, })") end end From fcec5e29477a6a672a32b4b1d2641f36e9db348a Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 16:56:14 -0700 Subject: [PATCH 03/11] Add rubocop as dev dependency --- rubocop-i18n.gemspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rubocop-i18n.gemspec b/rubocop-i18n.gemspec index b39c183..a555be6 100644 --- a/rubocop-i18n.gemspec +++ b/rubocop-i18n.gemspec @@ -1,6 +1,7 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +rubocop_version = "~> 0.49.0" Gem::Specification.new do |spec| spec.name = "rubocop-i18n" @@ -25,5 +26,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rb-readline" spec.add_development_dependency "pry" - spec.add_runtime_dependency "rubocop", "~> 0.49" + spec.add_development_dependency "rubocop", rubocop_version + spec.add_runtime_dependency "rubocop", rubocop_version end From 929efe0ee0101f1283d7e668b358172e0a0af3ba Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 17:04:03 -0700 Subject: [PATCH 04/11] Initial rubocop config and essential fixes --- .rubocop.yml | 1 + .rubocop_todo.yml | 363 ++++++++++++++++++ Rakefile | 8 +- lib/rubocop/cop/i18n/gettext.rb | 8 +- .../gettext/decorate_function_message_spec.rb | 4 +- 5 files changed, 377 insertions(+), 7 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..a11e54a --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,363 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-10-13 16:58:50 -0700 using RuboCop version 0.49.1. +# 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: 1 +# Cop supports --auto-correct. +Layout/BlockEndNewline: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/CommentIndentation: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'rubocop-i18n.gemspec' + - '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/gettext/decorate_string_formatting_using_percent_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'lib/rubocop/cop/i18n/gettext.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundAccessModifier: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundClassBody: + 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_interpolation.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: normal, rails +Layout/IndentationConsistency: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceAroundOperators: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/SpaceBeforeComma: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/SpaceInsideParens: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/TrailingWhitespace: + Exclude: + - 'spec/shared_examples.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/LiteralInInterpolation: + Exclude: + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'spec/shared_examples.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 4 +Metrics/AbcSize: + Max: 31 + +# Offense count: 5 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 68 + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 106 + +# Offense count: 3 +Metrics/CyclomaticComplexity: + Max: 8 + +# Offense count: 86 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 174 + +# Offense count: 6 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 26 + +# Offense count: 2 +Metrics/PerceivedComplexity: + Max: 8 + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + 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/gettext/decorate_string_formatting_using_percent_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 2 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/rubocop/cop/i18n/gettext.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, 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 +Style/FileName: + Exclude: + - 'lib/rubocop-i18n.rb' + +# Offense count: 7 +# Configuration parameters: SupportedStyles. +# SupportedStyles: annotated, template +Style/FormatStringToken: + EnforcedStyle: template + +# Offense count: 4 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + 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_interpolation.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'Rakefile' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 2 +# Configuration parameters: SupportedStyles. +# SupportedStyles: snake_case, camelCase +Style/MethodName: + EnforcedStyle: snake_case + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: both, prefix, postfix +Style/NegatedIf: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'rubocop-i18n.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' + +# Offense count: 44 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'Rakefile' + - 'bin/console' + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' + - 'rubocop-i18n.gemspec' + - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' + - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MinSize, SupportedStyles. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInLiteral: + Exclude: + - 'lib/rubocop/cop/i18n/gettext.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/UnneededInterpolation: + Exclude: + - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' + - 'spec/shared_examples.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Exclude: + - 'rubocop-i18n.gemspec' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 17 diff --git a/Rakefile b/Rakefile index b7e9ed5..fa47bfa 100644 --- a/Rakefile +++ b/Rakefile @@ -3,4 +3,10 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task :default => :test + +task :test => [:rubocop, :spec] + +task :rubocop do + sh 'rubocop -P' +end diff --git a/lib/rubocop/cop/i18n/gettext.rb b/lib/rubocop/cop/i18n/gettext.rb index badad36..c30f48b 100644 --- a/lib/rubocop/cop/i18n/gettext.rb +++ b/lib/rubocop/cop/i18n/gettext.rb @@ -4,13 +4,13 @@ module RuboCop module Cop module I18n module GetText - def self.SUPPORTED_METHODS + def self.supported_methods ['raise', 'fail'] end # Supports decorators from # * mutoh/gettext https://github.com/mutoh/gettext/blob/master/lib/gettext.rb # * grosser/fast_gettext https://github.com/grosser/fast_gettext/blob/master/lib/fast_gettext/translation.rb - def self.SUPPORTED_DECORATORS + def self.supported_decorators [ '_', 'n_', @@ -32,11 +32,11 @@ def self.SUPPORTED_DECORATORS end def self.supported_method?(method_name) - self.SUPPORTED_METHODS.include?(method_name) + supported_methods.include?(method_name) end def self.supported_decorator?(decorator_name) - self.SUPPORTED_DECORATORS.include?(decorator_name) + supported_decorators.include?(decorator_name) end end end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb index fb82ccd..b87168f 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb @@ -8,7 +8,7 @@ investigate(cop, source) } - RuboCop::Cop::I18n::GetText.SUPPORTED_METHODS.each do |function| + RuboCop::Cop::I18n::GetText.supported_methods.each do |function| context "#{function} with undecorated double-quote message" do it_behaves_like 'a_detecting_cop', "#{function}(\"a string\")", function, 'message string should be decorated' it_behaves_like 'a_fixing_cop', "#{function}(\"a string\")", "#{function}(_(\"a string\"))", function @@ -46,7 +46,7 @@ expect(cop.offenses.size).to eq(0) end end - RuboCop::Cop::I18n::GetText.SUPPORTED_DECORATORS.each do |decorator| + RuboCop::Cop::I18n::GetText.supported_decorators.each do |decorator| context "#{function} with the #{decorator} decorator" do it_behaves_like 'a_no_cop_required', "#{function}(#{decorator}(\"a string\"))", function it_behaves_like 'a_no_cop_required', "#{function}(#{decorator}('a string'))", function From 1e2e606fb1cde6a9ed2590c99d279a7cee38ee44 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 17:08:11 -0700 Subject: [PATCH 05/11] Rubocop auto-fixes --- .rubocop_todo.yml | 294 ------------------ Rakefile | 8 +- bin/console | 6 +- lib/rubocop/cop/i18n/gettext.rb | 37 +-- .../i18n/gettext/decorate_function_message.rb | 76 ++--- .../cop/i18n/gettext/decorate_string.rb | 5 +- ...e_string_formatting_using_interpolation.rb | 8 +- ...ecorate_string_formatting_using_percent.rb | 8 +- rubocop-i18n.gemspec | 33 +- .../gettext/decorate_function_message_spec.rb | 15 +- ...ing_formatting_using_interpolation_spec.rb | 15 +- ...te_string_formatting_using_percent_spec.rb | 15 +- .../cop/i18n/gettext/decorate_string_spec.rb | 13 +- spec/shared_examples.rb | 14 +- spec/spec_helper.rb | 7 +- 15 files changed, 130 insertions(+), 424 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a11e54a..93ebac5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,158 +5,6 @@ # 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: 1 -# Cop supports --auto-correct. -Layout/BlockEndNewline: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/CommentIndentation: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'rubocop-i18n.gemspec' - - '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/gettext/decorate_string_formatting_using_percent_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'lib/rubocop/cop/i18n/gettext.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundAccessModifier: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundClassBody: - 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_interpolation.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: normal, rails -Layout/IndentationConsistency: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Layout/LeadingCommentSpace: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Layout/SpaceAroundOperators: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/SpaceBeforeComma: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/SpaceInsideParens: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/TrailingWhitespace: - Exclude: - - 'spec/shared_examples.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Lint/LiteralInInterpolation: - Exclude: - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'spec/shared_examples.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. -Lint/UnusedMethodArgument: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - # Offense count: 4 Metrics/AbcSize: Max: 31 @@ -190,37 +38,6 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 8 -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - 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/gettext/decorate_string_formatting_using_percent_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - # Offense count: 2 Style/Documentation: Exclude: @@ -250,114 +67,3 @@ Style/GuardClause: - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'Rakefile' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 2 -# Configuration parameters: SupportedStyles. -# SupportedStyles: snake_case, camelCase -Style/MethodName: - EnforcedStyle: snake_case - -# Offense count: 1 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: both, prefix, postfix -Style/NegatedIf: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'rubocop-i18n.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb' - -# Offense count: 44 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Rakefile' - - 'bin/console' - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - - 'lib/rubocop/cop/i18n/gettext/decorate_string.rb' - - 'rubocop-i18n.gemspec' - - 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb' - - 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MinSize, SupportedStyles. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInLiteral: - Exclude: - - 'lib/rubocop/cop/i18n/gettext.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/UnneededInterpolation: - Exclude: - - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb' - - 'spec/shared_examples.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Exclude: - - 'rubocop-i18n.gemspec' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 17 diff --git a/Rakefile b/Rakefile index fa47bfa..b618cfb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,11 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :test +task default: :test -task :test => [:rubocop, :spec] +task test: %i[rubocop spec] task :rubocop do sh 'rubocop -P' diff --git a/bin/console b/bin/console index 11d498d..0404354 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "rubocop/i18n" +require 'bundler/setup' +require 'rubocop/i18n' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +10,5 @@ require "rubocop/i18n" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/lib/rubocop/cop/i18n/gettext.rb b/lib/rubocop/cop/i18n/gettext.rb index c30f48b..0211e3a 100644 --- a/lib/rubocop/cop/i18n/gettext.rb +++ b/lib/rubocop/cop/i18n/gettext.rb @@ -5,29 +5,30 @@ module Cop module I18n module GetText def self.supported_methods - ['raise', 'fail'] + %w[raise fail] end + # Supports decorators from # * mutoh/gettext https://github.com/mutoh/gettext/blob/master/lib/gettext.rb # * grosser/fast_gettext https://github.com/grosser/fast_gettext/blob/master/lib/fast_gettext/translation.rb def self.supported_decorators - [ - '_', - 'n_', - 'np_', - 'ns_', - 'N_', - 'Nn_', - 'D_', - 'Dn_', - 'Ds_', - 'Dns_', - 'd_', - 'dn_', - 'ds_', - 'dns_', - 'p_', - 's_', + %w[ + _ + n_ + np_ + ns_ + N_ + Nn_ + D_ + Dn_ + Ds_ + Dns_ + d_ + dn_ + ds_ + dns_ + p_ + s_ ] end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb b/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb index f8caf25..68b06d5 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_function_message.rb @@ -5,20 +5,21 @@ module GetText class DecorateFunctionMessage < Cop def on_send(node) method_name = node.loc.selector.source - return if !GetText.supported_method?(method_name) + return unless GetText.supported_method?(method_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && !already_decorated?(node) && (contains_string?(arg_nodes) || string_constant?(arg_nodes)) - if string_constant?(arg_nodes) - message_section = arg_nodes[1] - else - message_section = arg_nodes[0] - end + message_section = if string_constant?(arg_nodes) + arg_nodes[1] + else + arg_nodes[0] + end detect_and_report(node, message_section, method_name) end end private + def already_decorated?(node, parent = nil) parent ||= node @@ -36,10 +37,10 @@ def string_constant?(nodes) end def contains_string?(nodes) - nodes[0].inspect.include?(":str") || nodes[0].inspect.include?(":dstr") + nodes[0].inspect.include?(':str') || nodes[0].inspect.include?(':dstr') end - def detect_and_report(node, message_section, method_name) + def detect_and_report(_node, message_section, method_name) errors = how_bad_is_it(message_section) return if errors.empty? error_message = "'#{method_name}' function, " @@ -60,7 +61,7 @@ def how_bad_is_it(message_section) errors.push :multiline if message_section.multiline? errors.push :concatenation if concatenation_offense?(message_section) errors.push :interpolation if interpolation_offense?(message_section) - errors.push :no_decoration if !already_decorated?(message_section) + errors.push :no_decoration unless already_decorated?(message_section) # only display no_decoration, if that is the only problem. if errors.size > 1 && errors.include?(:no_decoration) @@ -84,7 +85,7 @@ def concatenation_offense?(node, parent = nil) def interpolation_offense?(node, parent = nil) parent ||= node - return true if node.class == RuboCop::AST::Node && node.dstr_type? + return true if node.class == RuboCop::AST::Node && node.dstr_type? return false unless node.respond_to?(:children) @@ -95,52 +96,51 @@ def autocorrect(node) if node.str_type? single_string_correct(node) elsif interpolation_offense?(node) -# interpolation_correct(node) + # interpolation_correct(node) end end def single_string_correct(node) - ->(corrector) { - corrector.insert_before(node.source_range , "_(") - corrector.insert_after(node.source_range , ")") } + lambda { |corrector| + corrector.insert_before(node.source_range, '_(') + corrector.insert_after(node.source_range, ')') + } end def interpolation_correct(node) - interpolated_values_string = "" + interpolated_values_string = '' count = 0 - ->(corrector) { + lambda { |corrector| node.children.each do |child| # dstrs are split into "str" segments and other segments. # The "other" segments are the interpolated values. - if child.type == :begin - value = child.children[0] - hash_key = "value" - if value.type == :lvar - # Use the variable's name as the format key - hash_key = value.loc.name.source - else - # These are placeholders that will manually need to be given - # a descriptive name - hash_key << "#{count}" - count += 1 - end - if interpolated_values_string.empty? - interpolated_values_string << "{ " - end - interpolated_values_string << "#{hash_key}: #{value.loc.expression.source}, " - - # Replace interpolation with format string - corrector.replace(child.loc.expression, "%{#{hash_key}}") + next unless child.type == :begin + value = child.children[0] + hash_key = 'value' + if value.type == :lvar + # Use the variable's name as the format key + hash_key = value.loc.name.source + else + # These are placeholders that will manually need to be given + # a descriptive name + hash_key << count.to_s + count += 1 end + if interpolated_values_string.empty? + interpolated_values_string << '{ ' + end + interpolated_values_string << "#{hash_key}: #{value.loc.expression.source}, " + + # Replace interpolation with format string + corrector.replace(child.loc.expression, "%{#{hash_key}}") end - if !interpolated_values_string.empty? - interpolated_values_string << "}" + unless interpolated_values_string.empty? + interpolated_values_string << '}' end corrector.insert_before(node.source_range, '_(') corrector.insert_after(node.source_range, ") % #{interpolated_values_string}") } end - end end end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string.rb b/lib/rubocop/cop/i18n/gettext/decorate_string.rb index 44995d7..d9c661c 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string.rb @@ -21,9 +21,9 @@ module GetText class DecorateString < Cop def on_str(node) str = node.children[0] - #ignore strings with no whitespace - are typically keywords or interpolation statements and cover the above commented-out statements + # ignore strings with no whitespace - are typically keywords or interpolation statements and cover the above commented-out statements if str !~ /^\S*$/ - add_offense(node, :expression, "decorator is missing around sentence") if node.loc.respond_to?(:begin) + add_offense(node, :expression, 'decorator is missing around sentence') if node.loc.respond_to?(:begin) end end @@ -32,7 +32,6 @@ def on_str(node) def message(node) node.receiver ? MSG_DEFAULT : MSG_SELF end - end end end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb index 0d5165c..2850dc0 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb @@ -22,7 +22,7 @@ module GetText class DecorateStringFormattingUsingInterpolation < Cop def on_send(node) decorator_name = node.loc.selector.source - return if !GetText.supported_decorator?(decorator_name) + return unless GetText.supported_decorator?(decorator_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && contains_string_formatting_with_interpolation?(arg_nodes) message_section = arg_nodes[0] @@ -31,6 +31,7 @@ def on_send(node) end private + def string_contains_interpolation_format?(str) str.match(/\#{[^}]+}/) end @@ -41,7 +42,7 @@ def contains_string_formatting_with_interpolation?(node) end if node.respond_to?(:type) - if node.type == :str or node.type == :dstr + if node.type == :str || node.type == :dstr return string_contains_interpolation_format?(node.source) end end @@ -49,9 +50,8 @@ def contains_string_formatting_with_interpolation?(node) if node.respond_to?(:children) return node.children.any? { |child| contains_string_formatting_with_interpolation?(child) } end - return false + false end - end end end diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb index 70b3ec0..b240c42 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb @@ -22,11 +22,11 @@ module GetText # _("result is %{detail}" % {detail: message}) # class DecorateStringFormattingUsingPercent < Cop - SUPPORTED_FORMATS = %w[b B d i o u x X e E f g G a A c p s] + SUPPORTED_FORMATS = %w[b B d i o u x X e E f g G a A c p s].freeze def on_send(node) decorator_name = node.loc.selector.source - return if !GetText.supported_decorator?(decorator_name) + return unless GetText.supported_decorator?(decorator_name) _, method_name, *arg_nodes = *node if !arg_nodes.empty? && contains_string_with_percent_format?(arg_nodes) message_section = arg_nodes[0] @@ -35,6 +35,7 @@ def on_send(node) end private + def string_contains_percent_format?(str) SUPPORTED_FORMATS.any? { |format| str.match(/%([-+])?[0-9]*(\.[0-9]*)?#{format}/) } end @@ -45,7 +46,7 @@ def contains_string_with_percent_format?(node) end if node.respond_to?(:type) - if node.type == :str or node.type == :dstr + if node.type == :str || node.type == :dstr return string_contains_percent_format?(node.source) end end @@ -55,7 +56,6 @@ def contains_string_with_percent_format?(node) end false end - end end end diff --git a/rubocop-i18n.gemspec b/rubocop-i18n.gemspec index a555be6..ab94133 100644 --- a/rubocop-i18n.gemspec +++ b/rubocop-i18n.gemspec @@ -1,31 +1,32 @@ # coding: utf-8 + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -rubocop_version = "~> 0.49.0" +rubocop_version = '~> 0.49.0' Gem::Specification.new do |spec| - spec.name = "rubocop-i18n" + spec.name = 'rubocop-i18n' spec.version = '1.1.0' - spec.authors = ["Puppet", "Brandon High", "TP Honey", "Helen Campbell"] - spec.email = ["team-modules@puppet.com", "brandon.high@puppet.com", "tp@puppet.com", "helen@puppet.com"] + spec.authors = ['Puppet', 'Brandon High', 'TP Honey', 'Helen Campbell'] + spec.email = ['team-modules@puppet.com', 'brandon.high@puppet.com', 'tp@puppet.com', 'helen@puppet.com'] - spec.summary = %q{RuboCop rules for i18n} - spec.description = %q{RuboCop rules for detecting and autocorrecting undecorated strings for i18n} - spec.homepage = "https://github.com/puppetlabs/rubocop-i18n" + spec.summary = 'RuboCop rules for i18n' + spec.description = 'RuboCop rules for detecting and autocorrecting undecorated strings for i18n' + spec.homepage = 'https://github.com/puppetlabs/rubocop-i18n' spec.license = 'Apache-2' spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_development_dependency "bundler", "~> 1.14" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rb-readline" - spec.add_development_dependency "pry" - spec.add_development_dependency "rubocop", rubocop_version - spec.add_runtime_dependency "rubocop", rubocop_version + spec.add_development_dependency 'bundler', '~> 1.14' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rb-readline' + spec.add_development_dependency 'pry' + spec.add_development_dependency 'rubocop', rubocop_version + spec.add_runtime_dependency 'rubocop', rubocop_version end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb index b87168f..5421ad7 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true + require 'spec_helper' describe RuboCop::Cop::I18n::GetText::DecorateFunctionMessage do let(:config) { RuboCop::Config.new } subject(:cop) { described_class.new(config) } - before(:each) { + before(:each) do investigate(cop, source) - } + end RuboCop::Cop::I18n::GetText.supported_methods.each do |function| context "#{function} with undecorated double-quote message" do @@ -32,7 +33,7 @@ end context "#{function} with interpolated string" do it_behaves_like 'a_detecting_cop', "#{function}(\"a string \#{var}\")", function, 'message should use correctly formatted interpolation' - #it_behaves_like 'a_fixing_cop', "#{function}(\"a string \#{var}\")", "#{function}(_(\"a string %{value0}\") % { value0: var, })", function + # it_behaves_like 'a_fixing_cop', "#{function}(\"a string \#{var}\")", "#{function}(_(\"a string %{value0}\") % { value0: var, })", function it_behaves_like 'a_no_cop_required', "#{function}(_(\"a string %{value0}\")) % { value0: var, }", function it_behaves_like 'a_no_cop_required', "#{function}(N_(\"a string %s\"))", function end @@ -55,8 +56,8 @@ end end end - context "real life examples," do - context "message is multiline with interpolated" do + context 'real life examples,' do + context 'message is multiline with interpolated' do let(:source) { "raise(Puppet::ParseError, \"mysql_password(): Wrong number of arguments \" \\\n \"given (\#{args.size} for 1)\")" } it 'has the correct error message' do @@ -70,8 +71,8 @@ end it 'autocorrects', broken: true do - corrected = autocorrect_source( "raise(Puppet::ParseError, \"mysql_password(): Wrong number of arguments \" \\ \"given (\#{args.size} for 1)\")" ) - expect(corrected).to eq("raise(Puppet::ParseError, _(\"a string %{value0}\") % { value0: var, })") + corrected = autocorrect_source("raise(Puppet::ParseError, \"mysql_password(): Wrong number of arguments \" \\ \"given (\#{args.size} for 1)\")") + expect(corrected).to eq('raise(Puppet::ParseError, _("a string %{value0}") % { value0: var, })') end end end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb index dfd0836..57ce85b 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true + require 'spec_helper' describe RuboCop::Cop::I18n::GetText::DecorateStringFormattingUsingInterpolation do - let(:config) {RuboCop::Config.new} - subject(:cop) {described_class.new(config)} - before(:each) { + let(:config) { RuboCop::Config.new } + subject(:cop) { described_class.new(config) } + before(:each) do investigate(cop, source) - } + end - decorators = ['_', 'n_', 'N_'] + decorators = %w[_ n_ N_] decorators.each do |decorator| - context "#{decorator} decoration not used" do - it_behaves_like 'a_no_cop_required', "thing(\"a #{true} that is not decorated\")" + it_behaves_like 'a_no_cop_required', 'thing("a true that is not decorated")' end context "#{decorator} decoration used but strings contain no \#{}" do @@ -39,5 +39,4 @@ it_behaves_like 'a_detecting_cop', "#{decorator}(CONSTANT, \"a \#{true}\")", '_', 'function, message string should not contain #{} formatting' end end - end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb index 93ee114..f405556 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true + require 'spec_helper' describe RuboCop::Cop::I18n::GetText::DecorateStringFormattingUsingPercent do - let(:config) {RuboCop::Config.new} - subject(:cop) {described_class.new(config)} - before(:each) { + let(:config) { RuboCop::Config.new } + subject(:cop) { described_class.new(config) } + before(:each) do investigate(cop, source) - } + end - decorators = ['_', 'n_', 'N_'] + decorators = %w[_ n_ N_] decorators.each do |decorator| - context "#{decorator} decoration not used" do - it_behaves_like 'a_no_cop_required', "thing(\"a %s that is not decorated\")" + it_behaves_like 'a_no_cop_required', 'thing("a %s that is not decorated")' end context "#{decorator} decoration used but strings contain no % format" do @@ -29,7 +29,6 @@ formats = %w[b B d i o u x X e E f g G a A c p s] formats.each do |format| - context "#{decorator} decoration with string % format" do it_behaves_like 'a_detecting_cop', "#{decorator}(\"a %#{format} string\")", '_', 'message string should not contain sprintf style formatting' it_behaves_like 'a_detecting_cop', "#{decorator}(\"a %#{format} string\" % [\"thing\"])", '_', 'message string should not contain sprintf style formatting' diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb index d3523ca..775f1b7 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe RuboCop::Cop::I18n::GetText::DecorateString do @@ -6,14 +7,14 @@ subject(:cop) { described_class.new(config) } # For some reason, this string isn't considered decorated. - #it_behaves_like 'accepts', '_("a string")' + # it_behaves_like 'accepts', '_("a string")' context 'undecorated string' do - let(:source) { -<<-RUBY -"a string" -RUBY - } + let(:source) do + <<-RUBY + "a string" + RUBY + end it 'rejects' do investigate(cop, source) diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 9c8e976..dc06075 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -7,8 +7,8 @@ end end -shared_examples 'a_detecting_cop' do |unfixed, function, expected_warning| - let(:source) { "#{unfixed}" } +shared_examples 'a_detecting_cop' do |unfixed, _function, expected_warning| + let(:source) { unfixed.to_s } it 'has the correct rubocop warning' do expect(cop.offenses[0]).not_to be_nil expect(cop.offenses[0].message).to include(expected_warning) @@ -19,15 +19,15 @@ end end -shared_examples 'a_no_cop_required' do |fixed, function| - let(:source) { "#{fixed}" } +shared_examples 'a_no_cop_required' do |fixed, _function| + let(:source) { fixed.to_s } it 'has no offenses found' do - expect(cop.offenses).to be_empty + expect(cop.offenses).to be_empty end end -shared_examples 'a_fixing_cop' do |unfixed, fixed, function| - let(:source) { "#{unfixed}" } +shared_examples 'a_fixing_cop' do |unfixed, fixed, _function| + let(:source) { unfixed.to_s } it 'autocorrects' do corrected = autocorrect_source(unfixed) expect(corrected).to eq(fixed) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8b8a4fe..ff8332d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,10 @@ -require "bundler/setup" -require "shared_functions" -require "shared_examples" +require 'bundler/setup' +require 'shared_functions' +require 'shared_examples' require 'rubocop/cop/i18n' require 'rubocop/rspec/cop_helper' RSpec.configure do |config| - # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples From a72bd8b4fc88d94ae1cf1b0d922b00246fef0e26 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 13 Oct 2017 17:12:46 -0700 Subject: [PATCH 06/11] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1730d0..9933524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## master (unreleased) + * Code restructure (no API changes) + * RuboCop lint fixes + ### 1.1.0 * Added support for DecorateStringFormattingUsingPercent From 2956455f8881da891e56617b5b8b858d18572639 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 16 Oct 2017 16:14:18 -0700 Subject: [PATCH 07/11] Cleanup documentation around SUPPORTED_DECORATORS --- .../decorate_string_formatting_using_interpolation.rb | 5 +++-- .../i18n/gettext/decorate_string_formatting_using_percent.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb index 2850dc0..29aaa3b 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb @@ -3,8 +3,9 @@ module Cop module I18n module GetText # When using an decorated string to support I18N, any strings inside the decoration should not contain - # the '#{}' interpolation string as this makes it hard to translate the strings. This cop checks the - # decorators listed in SUPPORTED_DECORATORS + # the '#{}' interpolation string as this makes it hard to translate the strings. + # + # Check GetText.supported_decorators for a list of decorators that can be used. # # @example # diff --git a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb index b240c42..e280540 100644 --- a/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb +++ b/lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb @@ -4,7 +4,7 @@ module I18n module GetText # When using a decorated string to support I18N, any strings inside the decoration should not contain sprintf # style formatting as this makes it hard to translate the string. This cop checks the decorators listed in - # SUPPORTED_DECORATORS and checks for each of the formats in SUPPORTED_FORMATS. NOTE: this cop does not + # GetText.supported_decorators and checks for each of the formats in SUPPORTED_FORMATS. NOTE: this cop does not # check for all possible sprintf formats. # # @example From 030a52b8749ad1b92a6782d83721a368bd9b4031 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 16 Oct 2017 16:15:15 -0700 Subject: [PATCH 08/11] Bump Y version for next release --- rubocop-i18n.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop-i18n.gemspec b/rubocop-i18n.gemspec index ab94133..2b85226 100644 --- a/rubocop-i18n.gemspec +++ b/rubocop-i18n.gemspec @@ -6,7 +6,7 @@ rubocop_version = '~> 0.49.0' Gem::Specification.new do |spec| spec.name = 'rubocop-i18n' - spec.version = '1.1.0' + spec.version = '1.2.0' spec.authors = ['Puppet', 'Brandon High', 'TP Honey', 'Helen Campbell'] spec.email = ['team-modules@puppet.com', 'brandon.high@puppet.com', 'tp@puppet.com', 'helen@puppet.com'] From fa9e2721ca0bbb8c390364aab0201b9f77bcb79d Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 16 Oct 2017 16:17:00 -0700 Subject: [PATCH 09/11] Fix incorrect lint auto-fix --- .../decorate_string_formatting_using_interpolation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb index 57ce85b..fdbd98a 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb @@ -12,7 +12,7 @@ decorators = %w[_ n_ N_] decorators.each do |decorator| context "#{decorator} decoration not used" do - it_behaves_like 'a_no_cop_required', 'thing("a true that is not decorated")' + it_behaves_like 'a_no_cop_required', 'thing("a \#{true} that is not decorated")' end context "#{decorator} decoration used but strings contain no \#{}" do From aa17aa349ee9b1a4652a7736919a42380098b87e Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 16 Oct 2017 16:19:45 -0700 Subject: [PATCH 10/11] Use GetText.supported_decorators in all specs --- .../decorate_string_formatting_using_interpolation_spec.rb | 3 +-- .../gettext/decorate_string_formatting_using_percent_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb index fdbd98a..e8bc0f0 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb @@ -9,8 +9,7 @@ investigate(cop, source) end - decorators = %w[_ n_ N_] - decorators.each do |decorator| + RuboCop::Cop::I18n::GetText.supported_decorators.each do |decorator| context "#{decorator} decoration not used" do it_behaves_like 'a_no_cop_required', 'thing("a \#{true} that is not decorated")' end diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb index f405556..56f91d4 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb @@ -9,8 +9,7 @@ investigate(cop, source) end - decorators = %w[_ n_ N_] - decorators.each do |decorator| + RuboCop::Cop::I18n::GetText.supported_decorators.each do |decorator| context "#{decorator} decoration not used" do it_behaves_like 'a_no_cop_required', 'thing("a %s that is not decorated")' end From d58df351c365d81135369de9a400685ada6046ee Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 16 Oct 2017 16:20:25 -0700 Subject: [PATCH 11/11] Remove commented out spec --- spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb b/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb index 775f1b7..3225614 100644 --- a/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb +++ b/spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb @@ -6,9 +6,6 @@ let(:config) { RuboCop::Config.new } subject(:cop) { described_class.new(config) } - # For some reason, this string isn't considered decorated. - # it_behaves_like 'accepts', '_("a string")' - context 'undecorated string' do let(:source) do <<-RUBY