diff --git a/.rubocop.yml b/.rubocop.yml index 61765c3323f..a34949cea87 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -120,6 +120,12 @@ Performance/CollectionLiteralInLoop: - 'Rakefile' - 'spec/**/*.rb' +Performance/EndWith: + SafeMultiline: false + +Performance/StartWith: + SafeMultiline: false + RSpec/StubbedMock: Enabled: false diff --git a/lib/rubocop/cop/layout/end_of_line.rb b/lib/rubocop/cop/layout/end_of_line.rb index 6b113df480d..879fc54e550 100644 --- a/lib/rubocop/cop/layout/end_of_line.rb +++ b/lib/rubocop/cop/layout/end_of_line.rb @@ -65,7 +65,7 @@ def on_new_investigation # If there is no LF on the last line, we don't care if there's no CR. def unimportant_missing_cr?(index, last_line, line) - style == :crlf && index == last_line - 1 && !/\n$/.match?(line) + style == :crlf && index == last_line - 1 && !line.end_with?("\n") end def offense_message(line) diff --git a/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb b/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb index ca873c188fe..869b586a1f5 100644 --- a/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +++ b/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb @@ -121,7 +121,8 @@ def simple_assignment?(node) end def capturing_variable?(name) - name && !/^_/.match?(name) + # TODO: Remove `Symbol#to_s` after supporting only Ruby >= 2.7. + name && !name.to_s.start_with?('_') end def branch?(node) diff --git a/lib/rubocop/cop/style/combinable_loops.rb b/lib/rubocop/cop/style/combinable_loops.rb index 7099436f8ee..74d566ab85d 100644 --- a/lib/rubocop/cop/style/combinable_loops.rb +++ b/lib/rubocop/cop/style/combinable_loops.rb @@ -75,8 +75,9 @@ def on_for(node) private def collection_looping_method?(node) - method_name = node.send_node.method_name - method_name.match?(/^each/) || method_name.match?(/_each$/) + # TODO: Remove `Symbol#to_s` after supporting only Ruby >= 2.7. + method_name = node.send_node.method_name.to_s + method_name.start_with?('each') || method_name.end_with?('_each') end def same_collection_looping?(node, sibling) diff --git a/lib/rubocop/cop/style/redundant_self_assignment.rb b/lib/rubocop/cop/style/redundant_self_assignment.rb index d02accc55ef..f040aa7da66 100644 --- a/lib/rubocop/cop/style/redundant_self_assignment.rb +++ b/lib/rubocop/cop/style/redundant_self_assignment.rb @@ -66,8 +66,8 @@ def on_lvasgn(node) alias on_gvasgn on_lvasgn def on_send(node) - # TODO: replace with #end_with? after supporting only ruby >= 2.7 - return unless node.method_name.match?(/=$/) + # TODO: Remove `Symbol#to_s` after supporting only Ruby >= 2.7. + return unless node.method_name.to_s.end_with?('=') return unless redundant_assignment?(node) message = format(MSG, method_name: node.first_argument.method_name)