diff --git a/Library/Homebrew/Gemfile.lock b/Library/Homebrew/Gemfile.lock index 93133be0da..d8f56dddaf 100644 --- a/Library/Homebrew/Gemfile.lock +++ b/Library/Homebrew/Gemfile.lock @@ -91,7 +91,7 @@ GEM unicode-display_width (>= 1.4.0, < 2.0) rubocop-ast (0.0.3) parser (>= 2.7.0.1) - rubocop-performance (1.5.2) + rubocop-performance (1.6.0) rubocop (>= 0.71.0) rubocop-rspec (1.39.0) rubocop (>= 0.68.1) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 32d958f069..e3f99669ca 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -89,7 +89,7 @@ module Cask args: ["list", service], sudo: with_sudo, print_stderr: false ).stdout - if plist_status.match?(/^\{/) + if plist_status.start_with?("{") command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) sleep 1 end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index deec12b9d6..82431558e7 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -984,7 +984,7 @@ module Homebrew except_audits = @except methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| - name = audit_method_name.gsub(/^audit_/, "") + name = audit_method_name.delete_prefix("audit_") if only_audits next unless only_audits.include?(name) elsif except_audits diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index 7e45247b75..0e41977c72 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -103,7 +103,7 @@ module Homebrew help_lines = command_help_lines(path) return if help_lines.blank? - Formatter.wrap(help_lines.join.gsub(/^ /, ""), COMMAND_DESC_WIDTH) + Formatter.wrap(help_lines.join.delete_prefix(" "), COMMAND_DESC_WIDTH) .sub("@hide_from_man_page ", "") .sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ") .gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}") diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index 429f5b8ebd..33c1ded388 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -230,7 +230,7 @@ module RuboCop # Use new-style archive downloads archive_gh_pattern = %r{https://.*github.*/(?:tar|zip)ball/} audit_urls(urls, archive_gh_pattern) do |_, url| - next if url.match?(/\.git$/) + next if url.end_with?(".git") problem "Use /archive/ URLs for GitHub tarballs (url is #{url})." end diff --git a/Library/Homebrew/test/cmd/shared_examples/args_parse.rb b/Library/Homebrew/test/cmd/shared_examples/args_parse.rb index 9cc16d455a..c9e8cc1d80 100644 --- a/Library/Homebrew/test/cmd/shared_examples/args_parse.rb +++ b/Library/Homebrew/test/cmd/shared_examples/args_parse.rb @@ -3,11 +3,12 @@ shared_examples "parseable arguments" do subject(:method_name) do |example| example.metadata[:example_group][:parent_example_group][:description] - .gsub(/^Homebrew\./, "") + .delete_prefix("Homebrew.") end let(:command_name) do - method_name.gsub(/_args$/, "").tr("_", "-") + method_name.delete_suffix("_args") + .tr("_", "-") end it "can parse arguments" do diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index d2ed6ce03a..f2a0fc25a7 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -68,7 +68,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 33, source: source }] - elsif patch_url.match?(%r{^http://trac\.macports\.org}) + elsif patch_url.start_with?("http://trac.macports.org") [{ message: <<~EOS.chomp, Patches from MacPorts Trac should be https://, not http: @@ -78,7 +78,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 5, source: source }] - elsif patch_url.match?(%r{^http://bugs\.debian\.org}) + elsif patch_url.start_with?("http://bugs.debian.org") [{ message: <<~EOS.chomp, Patches from Debian should be https://, not http: @@ -205,7 +205,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 37, source: source }] - elsif patch_url.match?(%r{^http://trac\.macports\.org}) + elsif patch_url.start_with?("http://trac.macports.org") [{ message: <<~EOS.chomp, Patches from MacPorts Trac should be https://, not http: @@ -215,7 +215,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 9, source: source }] - elsif patch_url.match?(%r{^http://bugs\.debian\.org}) + elsif patch_url.start_with?("http://bugs.debian.org") [{ message: <<~EOS.chomp, Patches from Debian should be https://, not http: diff --git a/Library/Homebrew/vendor/bundle/bundler/setup.rb b/Library/Homebrew/vendor/bundle/bundler/setup.rb index 41a0f0c253..4dd5a37499 100644 --- a/Library/Homebrew/vendor/bundle/bundler/setup.rb +++ b/Library/Homebrew/vendor/bundle/bundler/setup.rb @@ -12,6 +12,8 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.3.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.0.3.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.0/lib" $:.unshift "#{path}/" +$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/byebug-11.1.3" +$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/byebug-11.1.3/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/connection_pool-2.2.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/json-2.3.0" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/json-2.3.0/lib" @@ -59,10 +61,10 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-3.9.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-its-1.3.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-retry-0.6.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib" +$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-0.0.3/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.7.0/lib" -$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.83.0/lib" -$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.5.2/lib" +$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.84.0/lib" +$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.6.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.39.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib" -$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/byebug-11.1.3/lib" diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/config/default.yml b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/config/default.yml similarity index 93% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/config/default.yml rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/config/default.yml index 13740d9418..e6b3c65f69 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/config/default.yml +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/config/default.yml @@ -1,5 +1,10 @@ # This is the default configuration file. +Performance/BindCall: + Description: 'Use `bind_call(obj, args, ...)` instead of `bind(obj).call(args, ...)`.' + Enabled: true + VersionAdded: '1.6' + Performance/Caller: Description: >- Use `caller(n..n)` instead of `caller`. @@ -21,6 +26,7 @@ Performance/Casecmp: Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`.. Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code' Enabled: true + Safe: false VersionAdded: '0.36' Performance/ChainArrayAllocation: @@ -49,6 +55,16 @@ Performance/Count: VersionAdded: '0.31' VersionChanged: '1.5' +Performance/DeletePrefix: + Description: 'Use `delete_prefix` instead of `gsub`.' + Enabled: true + VersionAdded: '1.6' + +Performance/DeleteSuffix: + Description: 'Use `delete_suffix` instead of `gsub`.' + Enabled: true + VersionAdded: '1.6' + Performance/Detect: Description: >- Use `detect` instead of `select.first`, `find_all.first`, @@ -87,7 +103,7 @@ Performance/EndWith: VersionChanged: '0.44' Performance/FixedSize: - Description: 'Do not compute the size of statically sized objects except in constants' + Description: 'Do not compute the size of statically sized objects except in constants.' Enabled: true VersionAdded: '0.35' @@ -95,7 +111,7 @@ Performance/FlatMap: Description: >- Use `Enumerable#flat_map` instead of `Enumerable#map...Array#flatten(1)` - or `Enumberable#collect..Array#flatten(1)` + or `Enumberable#collect..Array#flatten(1)`. Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code' Enabled: true VersionAdded: '0.30' @@ -106,7 +122,7 @@ Performance/FlatMap: # `flatten` without any parameters can flatten multiple levels. Performance/InefficientHashSearch: - Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`' + Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`.' Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashkey-instead-of-hashkeysinclude-code' Enabled: true VersionAdded: '0.56' diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop-performance.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop-performance.rb similarity index 100% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop-performance.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop-performance.rb diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/mixin/regexp_metacharacter.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/mixin/regexp_metacharacter.rb new file mode 100644 index 0000000000..68c7c49840 --- /dev/null +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/mixin/regexp_metacharacter.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + # Common functionality for handling regexp metacharacters. + module RegexpMetacharacter + def literal_at_start?(regex_str) + # is this regexp 'literal' in the sense of only matching literal + # chars, rather than using metachars like `.` and `*` and so on? + # also, is it anchored at the start of the string? + # (tricky: \s, \d, and so on are metacharacters, but other characters + # escaped with a slash are just literals. LITERAL_REGEX takes all + # that into account.) + regex_str =~ /\A(\\A|\^)(?:#{Util::LITERAL_REGEX})+\z/ + end + + def literal_at_end?(regex_str) + # is this regexp 'literal' in the sense of only matching literal + # chars, rather than using metachars like . and * and so on? + # also, is it anchored at the end of the string? + regex_str =~ /\A(?:#{Util::LITERAL_REGEX})+(\\z|\$)\z/ + end + + def drop_start_metacharacter(regexp_string) + if regexp_string.start_with?('\\A') + regexp_string[2..-1] # drop `\A` anchor + else + regexp_string[1..-1] # drop `^` anchor + end + end + + def drop_end_metacharacter(regexp_string) + if regexp_string.end_with?('\\z') + regexp_string.chomp('\z') # drop `\z` anchor + else + regexp_string.chop # drop `$` anchor + end + end + end + end +end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/bind_call.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/bind_call.rb new file mode 100644 index 0000000000..cf671fde25 --- /dev/null +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/bind_call.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Performance + # In Ruby 2.7, `UnboundMethod#bind_call` has been added. + # + # This cop identifies places where `bind(obj).call(args, ...)` + # can be replaced by `bind_call(obj, args, ...)`. + # + # The `bind_call(obj, args, ...)` method is faster than + # `bind(obj).call(args, ...)`. + # + # @example + # # bad + # umethod.bind(obj).call(foo, bar) + # umethod.bind(obj).(foo, bar) + # + # # good + # umethod.bind_call(obj, foo, bar) + # + class BindCall < Cop + include RangeHelp + extend TargetRubyVersion + + minimum_target_ruby_version 2.7 + + MSG = 'Use `bind_call(%s%s%s)` ' \ + 'instead of `bind(%s).call(%s)`.' + + def_node_matcher :bind_with_call_method?, <<~PATTERN + (send + $(send + (send nil? _) :bind + $(...)) :call + $...) + PATTERN + + def on_send(node) + bind_with_call_method?(node) do |receiver, bind_arg, call_args_node| + range = correction_range(receiver, node) + + call_args = build_call_args(call_args_node) + + message = message(bind_arg.source, call_args) + + add_offense(node, location: range, message: message) + end + end + + def autocorrect(node) + receiver, bind_arg, call_args_node = bind_with_call_method?(node) + + range = correction_range(receiver, node) + + call_args = build_call_args(call_args_node) + call_args = ", #{call_args}" unless call_args.empty? + + replacement_method = "bind_call(#{bind_arg.source}#{call_args})" + + lambda do |corrector| + corrector.replace(range, replacement_method) + end + end + + private + + def message(bind_arg, call_args) + comma = call_args.empty? ? '' : ', ' + + format(MSG, bind_arg: bind_arg, comma: comma, call_args: call_args) + end + + def correction_range(receiver, node) + location_of_bind = receiver.loc.selector.begin_pos + location_of_call = node.loc.end.end_pos + + range_between(location_of_bind, location_of_call) + end + + def build_call_args(call_args_node) + call_args_node.map(&:source).join(', ') + end + end + end + end +end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/caller.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/caller.rb similarity index 93% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/caller.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/caller.rb index 9cc82243d4..7f9d22887f 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/caller.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/caller.rb @@ -24,14 +24,14 @@ module RuboCop MSG_FIRST = 'Use `%s(%d..%d).first`' \ ' instead of `%s.first`.' - def_node_matcher :slow_caller?, <<-PATTERN + def_node_matcher :slow_caller?, <<~PATTERN { (send nil? {:caller :caller_locations}) (send nil? {:caller :caller_locations} int) } PATTERN - def_node_matcher :caller_with_scope_method?, <<-PATTERN + def_node_matcher :caller_with_scope_method?, <<~PATTERN { (send #slow_caller? :first) (send #slow_caller? :[] int) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/case_when_splat.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/case_when_splat.rb similarity index 100% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/case_when_splat.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/case_when_splat.rb diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/casecmp.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/casecmp.rb similarity index 91% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/casecmp.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/casecmp.rb index c411eca255..cfb0c709cb 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/casecmp.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/casecmp.rb @@ -5,6 +5,8 @@ module RuboCop module Performance # This cop identifies places where a case-insensitive string comparison # can better be implemented using `casecmp`. + # This cop is unsafe because `String#casecmp` and `String#casecmp?` behave + # differently when using Non-ASCII characters. # # @example # # bad @@ -21,21 +23,21 @@ module RuboCop MSG = 'Use `%s` instead of `%s`.' CASE_METHODS = %i[downcase upcase].freeze - def_node_matcher :downcase_eq, <<-PATTERN + def_node_matcher :downcase_eq, <<~PATTERN (send $(send _ ${:downcase :upcase}) ${:== :eql? :!=} ${str (send _ {:downcase :upcase} ...) (begin str)}) PATTERN - def_node_matcher :eq_downcase, <<-PATTERN + def_node_matcher :eq_downcase, <<~PATTERN (send {str (send _ {:downcase :upcase} ...) (begin str)} ${:== :eql? :!=} $(send _ ${:downcase :upcase})) PATTERN - def_node_matcher :downcase_downcase, <<-PATTERN + def_node_matcher :downcase_downcase, <<~PATTERN (send $(send _ ${:downcase :upcase}) ${:== :eql? :!=} diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/chain_array_allocation.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/chain_array_allocation.rb similarity index 98% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/chain_array_allocation.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/chain_array_allocation.rb index 49620cea8e..140dfa48ed 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/chain_array_allocation.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/chain_array_allocation.rb @@ -51,7 +51,7 @@ module RuboCop '(followed by `return array` if required) instead of chaining '\ '`%s...%s`.' - def_node_matcher :flat_map_candidate?, <<-PATTERN + def_node_matcher :flat_map_candidate?, <<~PATTERN { (send (send _ ${#{RETURN_NEW_ARRAY_WHEN_ARGS}} {int lvar ivar cvar gvar}) ${#{HAS_MUTATION_ALTERNATIVE}} $...) (send (block (send _ ${#{ALWAYS_RETURNS_NEW_ARRAY} }) ...) ${#{HAS_MUTATION_ALTERNATIVE}} $...) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/compare_with_block.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/compare_with_block.rb similarity index 97% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/compare_with_block.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/compare_with_block.rb index 040e6e47b2..01c1393a5d 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/compare_with_block.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/compare_with_block.rb @@ -30,14 +30,14 @@ module RuboCop '`%s { |%s, %s| %s ' \ '<=> %s }`.' - def_node_matcher :compare?, <<-PATTERN + def_node_matcher :compare?, <<~PATTERN (block $(send _ {:sort :min :max}) (args (arg $_a) (arg $_b)) $send) PATTERN - def_node_matcher :replaceable_body?, <<-PATTERN + def_node_matcher :replaceable_body?, <<~PATTERN (send (send (lvar %1) $_method $...) :<=> diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/count.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/count.rb similarity index 98% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/count.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/count.rb index 80a6e42627..4a2eb1df83 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/count.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/count.rb @@ -42,7 +42,7 @@ module RuboCop MSG = 'Use `count` instead of `%s...%s`.' - def_node_matcher :count_candidate?, <<-PATTERN + def_node_matcher :count_candidate?, <<~PATTERN { (send (block $(send _ ${:select :reject}) ...) ${:count :length :size}) (send $(send _ ${:select :reject} (:block_pass _)) ${:count :length :size}) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_prefix.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_prefix.rb new file mode 100644 index 0000000000..f2867720dc --- /dev/null +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_prefix.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Performance + # In Ruby 2.5, `String#delete_prefix` has been added. + # + # This cop identifies places where `gsub(/\Aprefix/, '')` + # can be replaced by `delete_prefix('prefix')`. + # + # The `delete_prefix('prefix')` method is faster than + # `gsub(/\Aprefix/, '')`. + # + # @example + # + # # bad + # str.gsub(/\Aprefix/, '') + # str.gsub!(/\Aprefix/, '') + # str.gsub(/^prefix/, '') + # str.gsub!(/^prefix/, '') + # + # # good + # str.delete_prefix('prefix') + # str.delete_prefix!('prefix') + # + class DeletePrefix < Cop + extend TargetRubyVersion + include RegexpMetacharacter + + minimum_target_ruby_version 2.5 + + MSG = 'Use `%s` instead of `%s`.' + + PREFERRED_METHODS = { + gsub: :delete_prefix, + gsub!: :delete_prefix! + }.freeze + + def_node_matcher :gsub_method?, <<~PATTERN + (send $!nil? ${:gsub :gsub!} (regexp (str $#literal_at_start?) (regopt)) (str $_)) + PATTERN + + def on_send(node) + gsub_method?(node) do |_, bad_method, _, replace_string| + return unless replace_string.blank? + + good_method = PREFERRED_METHODS[bad_method] + + message = format(MSG, current: bad_method, prefer: good_method) + + add_offense(node, location: :selector, message: message) + end + end + + def autocorrect(node) + gsub_method?(node) do |receiver, bad_method, regexp_str, _| + lambda do |corrector| + good_method = PREFERRED_METHODS[bad_method] + regexp_str = drop_start_metacharacter(regexp_str) + regexp_str = interpret_string_escapes(regexp_str) + string_literal = to_string_literal(regexp_str) + + new_code = "#{receiver.source}.#{good_method}(#{string_literal})" + + corrector.replace(node, new_code) + end + end + end + end + end + end +end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_suffix.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_suffix.rb new file mode 100644 index 0000000000..8d727dd57f --- /dev/null +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/delete_suffix.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Performance + # In Ruby 2.5, `String#delete_suffix` has been added. + # + # This cop identifies places where `gsub(/suffix\z/, '')` + # can be replaced by `delete_suffix('suffix')`. + # + # The `delete_suffix('suffix')` method is faster than + # `gsub(/suffix\z/, '')`. + # + # @example + # + # # bad + # str.gsub(/suffix\z/, '') + # str.gsub!(/suffix\z/, '') + # str.gsub(/suffix$/, '') + # str.gsub!(/suffix$/, '') + # + # # good + # str.delete_suffix('suffix') + # str.delete_suffix!('suffix') + # + class DeleteSuffix < Cop + extend TargetRubyVersion + include RegexpMetacharacter + + minimum_target_ruby_version 2.5 + + MSG = 'Use `%s` instead of `%s`.' + + PREFERRED_METHODS = { + gsub: :delete_suffix, + gsub!: :delete_suffix! + }.freeze + + def_node_matcher :gsub_method?, <<~PATTERN + (send $!nil? ${:gsub :gsub!} (regexp (str $#literal_at_end?) (regopt)) (str $_)) + PATTERN + + def on_send(node) + gsub_method?(node) do |_, bad_method, _, replace_string| + return unless replace_string.blank? + + good_method = PREFERRED_METHODS[bad_method] + + message = format(MSG, current: bad_method, prefer: good_method) + + add_offense(node, location: :selector, message: message) + end + end + + def autocorrect(node) + gsub_method?(node) do |receiver, bad_method, regexp_str, _| + lambda do |corrector| + good_method = PREFERRED_METHODS[bad_method] + regexp_str = drop_end_metacharacter(regexp_str) + regexp_str = interpret_string_escapes(regexp_str) + string_literal = to_string_literal(regexp_str) + + new_code = "#{receiver.source}.#{good_method}(#{string_literal})" + + corrector.replace(node, new_code) + end + end + end + end + end + end +end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/detect.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/detect.rb similarity index 98% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/detect.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/detect.rb index f1aa75be8d..958b4e8444 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/detect.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/detect.rb @@ -28,7 +28,7 @@ module RuboCop REVERSE_MSG = 'Use `reverse.%s` instead of ' \ '`%s.%s`.' - def_node_matcher :detect_candidate?, <<-PATTERN + def_node_matcher :detect_candidate?, <<~PATTERN { (send $(block (send _ {:select :find_all}) ...) ${:first :last} $...) (send $(send _ {:select :find_all} ...) ${:first :last} $...) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/double_start_end_with.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/double_start_end_with.rb similarity index 95% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/double_start_end_with.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/double_start_end_with.rb index 530c41d424..92e7e385be 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/double_start_end_with.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/double_start_end_with.rb @@ -75,13 +75,13 @@ module RuboCop cop_config['IncludeActiveSupportAliases'] end - def_node_matcher :two_start_end_with_calls, <<-PATTERN + def_node_matcher :two_start_end_with_calls, <<~PATTERN (or (send $_recv [{:start_with? :end_with?} $_method] $...) (send _recv _method $...)) PATTERN - def_node_matcher :check_with_active_support_aliases, <<-PATTERN + def_node_matcher :check_with_active_support_aliases, <<~PATTERN (or (send $_recv [{:start_with? :starts_with? :end_with? :ends_with?} $_method] diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/end_with.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/end_with.rb similarity index 77% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/end_with.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/end_with.rb index 66f43a6ce6..584d2eb6f1 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/end_with.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/end_with.rb @@ -15,26 +15,27 @@ module RuboCop # 'abc'.match(/bc\Z/) # /bc\Z/.match('abc') # + # 'abc'.match?(/bc$/) + # /bc$/.match?('abc') + # 'abc' =~ /bc$/ + # /bc$/ =~ 'abc' + # 'abc'.match(/bc$/) + # /bc$/.match('abc') + # # # good # 'abc'.end_with?('bc') class EndWith < Cop + include RegexpMetacharacter + MSG = 'Use `String#end_with?` instead of a regex match anchored to ' \ 'the end of the string.' - SINGLE_QUOTE = "'" - def_node_matcher :redundant_regex?, <<-PATTERN + def_node_matcher :redundant_regex?, <<~PATTERN {(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_end?) (regopt))) (send (regexp (str $#literal_at_end?) (regopt)) {:match :match?} $_) (match-with-lvasgn (regexp (str $#literal_at_end?) (regopt)) $_)} PATTERN - def literal_at_end?(regex_str) - # is this regexp 'literal' in the sense of only matching literal - # chars, rather than using metachars like . and * and so on? - # also, is it anchored at the end of the string? - regex_str =~ /\A(?:#{LITERAL_REGEX})+\\z\z/ - end - def on_send(node) return unless redundant_regex?(node) @@ -45,7 +46,7 @@ module RuboCop def autocorrect(node) redundant_regex?(node) do |receiver, regex_str| receiver, regex_str = regex_str, receiver if receiver.is_a?(String) - regex_str = regex_str[0..-3] # drop \Z anchor + regex_str = drop_end_metacharacter(regex_str) regex_str = interpret_string_escapes(regex_str) lambda do |corrector| diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/fixed_size.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/fixed_size.rb similarity index 97% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/fixed_size.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/fixed_size.rb index c3a0beb481..76be44259c 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/fixed_size.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/fixed_size.rb @@ -48,7 +48,7 @@ module RuboCop class FixedSize < Cop MSG = 'Do not compute the size of statically sized objects.' - def_node_matcher :counter, <<-MATCHER + def_node_matcher :counter, <<~MATCHER (send ${array hash str sym} {:count :length :size} $...) MATCHER diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/flat_map.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/flat_map.rb similarity index 97% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/flat_map.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/flat_map.rb index b5b91876a7..de4677a444 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/flat_map.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/flat_map.rb @@ -22,7 +22,7 @@ module RuboCop 'and `flatten` can be used to flatten ' \ 'multiple levels.' - def_node_matcher :flat_map_candidate?, <<-PATTERN + def_node_matcher :flat_map_candidate?, <<~PATTERN (send { (block $(send _ ${:collect :map}) ...) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/inefficient_hash_search.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/inefficient_hash_search.rb similarity index 98% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/inefficient_hash_search.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/inefficient_hash_search.rb index 0a4a1cc0b2..b72063faef 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/inefficient_hash_search.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/inefficient_hash_search.rb @@ -37,7 +37,7 @@ module RuboCop # h = { a: 1, b: 2 }; h.value?(nil) # class InefficientHashSearch < Cop - def_node_matcher :inefficient_include?, <<-PATTERN + def_node_matcher :inefficient_include?, <<~PATTERN (send (send $_ {:keys :values}) :include? _) PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/open_struct.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/open_struct.rb similarity index 96% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/open_struct.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/open_struct.rb index d3d3e212aa..192bc81239 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/open_struct.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/open_struct.rb @@ -31,7 +31,7 @@ module RuboCop MSG = 'Consider using `Struct` over `OpenStruct` ' \ 'to optimize the performance.' - def_node_matcher :open_struct, <<-PATTERN + def_node_matcher :open_struct, <<~PATTERN (send (const {nil? cbase} :OpenStruct) :new ...) PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/range_include.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/range_include.rb similarity index 96% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/range_include.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/range_include.rb index 77eebc8bbc..0e49753c54 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/range_include.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/range_include.rb @@ -31,7 +31,7 @@ module RuboCop # Right now, we only detect direct calls on a Range literal # (We don't even catch it if the Range is in double parens) - def_node_matcher :range_include, <<-PATTERN + def_node_matcher :range_include, <<~PATTERN (send {irange erange (begin {irange erange})} :include? ...) PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_block_call.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_block_call.rb similarity index 93% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_block_call.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_block_call.rb index 315deac115..1301ae821e 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_block_call.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_block_call.rb @@ -29,16 +29,16 @@ module RuboCop CLOSE_PAREN = ')' SPACE = ' ' - def_node_matcher :blockarg_def, <<-PATTERN + def_node_matcher :blockarg_def, <<~PATTERN {(def _ (args ... (blockarg $_)) $_) (defs _ _ (args ... (blockarg $_)) $_)} PATTERN - def_node_search :blockarg_calls, <<-PATTERN + def_node_search :blockarg_calls, <<~PATTERN (send (lvar %1) :call ...) PATTERN - def_node_search :blockarg_assigned?, <<-PATTERN + def_node_search :blockarg_assigned?, <<~PATTERN (lvasgn %1 ...) PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_match.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_match.rb similarity index 93% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_match.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_match.rb index b1eabc8ae4..f0bfecde0a 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_match.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_match.rb @@ -23,12 +23,12 @@ module RuboCop # 'match' is a fairly generic name, so we don't flag it unless we see # a string or regexp literal on one side or the other - def_node_matcher :match_call?, <<-PATTERN + def_node_matcher :match_call?, <<~PATTERN {(send {str regexp} :match _) (send !nil? :match {str regexp})} PATTERN - def_node_matcher :only_truthiness_matters?, <<-PATTERN + def_node_matcher :only_truthiness_matters?, <<~PATTERN ^({if while until case while_post until_post} equal?(%0) ...) PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_merge.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_merge.rb similarity index 89% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_merge.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_merge.rb index d93ca155d9..bfb7347aec 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/redundant_merge.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/redundant_merge.rb @@ -5,11 +5,25 @@ module RuboCop module Performance # This cop identifies places where `Hash#merge!` can be replaced by # `Hash#[]=`. + # You can set the maximum number of key-value pairs to consider + # an offense with `MaxKeyValuePairs`. # # @example + # # bad # hash.merge!(a: 1) # hash.merge!({'key' => 'value'}) + # + # # good + # hash[:a] = 1 + # hash['key'] = 'value' + # + # @example MaxKeyValuePairs: 2 (default) + # # bad # hash.merge!(a: 1, b: 2) + # + # # good + # hash[:a] = 1 + # hash[:b] = 2 class RedundantMerge < Cop AREF_ASGN = '%s[%s] = %s' MSG = 'Use `%s` instead of `%s`.' @@ -20,11 +34,11 @@ module RuboCop %send RUBY - def_node_matcher :redundant_merge_candidate, <<-PATTERN + def_node_matcher :redundant_merge_candidate, <<~PATTERN (send $!nil? :merge! [(hash $...) !kwsplat_type?]) PATTERN - def_node_matcher :modifier_flow_control?, <<-PATTERN + def_node_matcher :modifier_flow_control?, <<~PATTERN [{if while until} modifier_form?] PATTERN @@ -168,13 +182,11 @@ module RuboCop end def unwind(receiver) - while receiver.respond_to?(:send_type?) && receiver.send_type? - receiver, = *receiver - end + receiver, = *receiver while receiver.respond_to?(:send_type?) && receiver.send_type? receiver end - def_node_matcher :each_with_object_node, <<-PATTERN + def_node_matcher :each_with_object_node, <<~PATTERN (block (send _ :each_with_object _) (args _ $_) ...) PATTERN end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/regexp_match.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/regexp_match.rb similarity index 92% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/regexp_match.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/regexp_match.rb index e59ea7f63d..bc5579ec05 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/regexp_match.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/regexp_match.rb @@ -73,32 +73,28 @@ module RuboCop # end # end class RegexpMatch < Cop - extend TargetRubyVersion - - minimum_target_ruby_version 2.4 - # Constants are included in this list because it is unlikely that # someone will store `nil` as a constant and then use it for comparison TYPES_IMPLEMENTING_MATCH = %i[const regexp str sym].freeze MSG = 'Use `match?` instead of `%s` when `MatchData` ' \ 'is not used.' - def_node_matcher :match_method?, <<-PATTERN + def_node_matcher :match_method?, <<~PATTERN { (send _recv :match {regexp str sym}) (send {regexp str sym} :match _) } PATTERN - def_node_matcher :match_with_int_arg_method?, <<-PATTERN + def_node_matcher :match_with_int_arg_method?, <<~PATTERN (send _recv :match _ (int ...)) PATTERN - def_node_matcher :match_operator?, <<-PATTERN + def_node_matcher :match_operator?, <<~PATTERN (send !nil? {:=~ :!~} !nil?) PATTERN - def_node_matcher :match_threequals?, <<-PATTERN + def_node_matcher :match_threequals?, <<~PATTERN (send (regexp (str _) {(regopt) (regopt _)}) :=== !nil?) PATTERN @@ -109,7 +105,7 @@ module RuboCop regexp.to_regexp.named_captures.empty? end - MATCH_NODE_PATTERN = <<-PATTERN + MATCH_NODE_PATTERN = <<~PATTERN { #match_method? #match_with_int_arg_method? @@ -122,7 +118,7 @@ module RuboCop def_node_matcher :match_node?, MATCH_NODE_PATTERN def_node_search :search_match_nodes, MATCH_NODE_PATTERN - def_node_search :last_matches, <<-PATTERN + def_node_search :last_matches, <<~PATTERN { (send (const nil? :Regexp) :last_match) (send (const nil? :Regexp) :last_match _) @@ -256,6 +252,13 @@ module RuboCop def correct_operator(corrector, recv, arg, oper = nil) op_range = correction_range(recv, arg) + replace_with_match_predicate_method(corrector, recv, arg, op_range) + + corrector.insert_after(arg.loc.expression, ')') unless op_range.source.end_with?('(') + corrector.insert_before(recv.loc.expression, '!') if oper == :!~ + end + + def replace_with_match_predicate_method(corrector, recv, arg, op_range) if TYPES_IMPLEMENTING_MATCH.include?(recv.type) corrector.replace(op_range, '.match?(') elsif TYPES_IMPLEMENTING_MATCH.include?(arg.type) @@ -264,9 +267,6 @@ module RuboCop else corrector.replace(op_range, '&.match?(') end - - corrector.insert_after(arg.loc.expression, ')') - corrector.insert_before(recv.loc.expression, '!') if oper == :!~ end def swap_receiver_and_arg(corrector, recv, arg) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/reverse_each.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/reverse_each.rb similarity index 82% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/reverse_each.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/reverse_each.rb index 6c6fdfba14..09a8214123 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/reverse_each.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/reverse_each.rb @@ -18,7 +18,7 @@ module RuboCop MSG = 'Use `reverse_each` instead of `reverse.each`.' UNDERSCORE = '_' - def_node_matcher :reverse_each?, <<-MATCHER + def_node_matcher :reverse_each?, <<~MATCHER (send $(send _ :reverse) :each) MATCHER @@ -34,7 +34,8 @@ module RuboCop end def autocorrect(node) - ->(corrector) { corrector.replace(node.loc.dot, UNDERSCORE) } + range = range_between(node.loc.dot.begin_pos, node.loc.selector.begin_pos) + ->(corrector) { corrector.replace(range, UNDERSCORE) } end end end diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/size.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/size.rb similarity index 100% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/size.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/size.rb diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/start_with.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/start_with.rb similarity index 70% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/start_with.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/start_with.rb index b4a7cae8a1..18733d4bdf 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/start_with.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/start_with.rb @@ -15,29 +15,27 @@ module RuboCop # 'abc'.match(/\Aab/) # /\Aab/.match('abc') # + # 'abc'.match?(/^ab/) + # /^ab/.match?('abc') + # 'abc' =~ /^ab/ + # /^ab/ =~ 'abc' + # 'abc'.match(/^ab/) + # /^ab/.match('abc') + # # # good # 'abc'.start_with?('ab') class StartWith < Cop + include RegexpMetacharacter + MSG = 'Use `String#start_with?` instead of a regex match anchored to ' \ 'the beginning of the string.' - SINGLE_QUOTE = "'" - def_node_matcher :redundant_regex?, <<-PATTERN + def_node_matcher :redundant_regex?, <<~PATTERN {(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_start?) (regopt))) (send (regexp (str $#literal_at_start?) (regopt)) {:match :match?} $_) (match-with-lvasgn (regexp (str $#literal_at_start?) (regopt)) $_)} PATTERN - def literal_at_start?(regex_str) - # is this regexp 'literal' in the sense of only matching literal - # chars, rather than using metachars like `.` and `*` and so on? - # also, is it anchored at the start of the string? - # (tricky: \s, \d, and so on are metacharacters, but other characters - # escaped with a slash are just literals. LITERAL_REGEX takes all - # that into account.) - regex_str =~ /\A\\A(?:#{LITERAL_REGEX})+\z/ - end - def on_send(node) return unless redundant_regex?(node) @@ -48,7 +46,7 @@ module RuboCop def autocorrect(node) redundant_regex?(node) do |receiver, regex_str| receiver, regex_str = regex_str, receiver if receiver.is_a?(String) - regex_str = regex_str[2..-1] # drop \A anchor + regex_str = drop_start_metacharacter(regex_str) regex_str = interpret_string_escapes(regex_str) lambda do |corrector| diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/string_replacement.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/string_replacement.rb similarity index 91% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/string_replacement.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/string_replacement.rb index b5b0a4dafd..e6dab7e396 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/string_replacement.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/string_replacement.rb @@ -26,9 +26,8 @@ module RuboCop DELETE = 'delete' TR = 'tr' BANG = '!' - SINGLE_QUOTE = "'" - def_node_matcher :string_replacement?, <<-PATTERN + def_node_matcher :string_replacement?, <<~PATTERN (send _ {:gsub :gsub!} ${regexp str (send (const nil? :Regexp) {:new :compile} _)} $str) @@ -48,9 +47,7 @@ module RuboCop first_source, = first_source(first_param) second_source, = *second_param - unless first_param.str_type? - first_source = interpret_string_escapes(first_source) - end + first_source = interpret_string_escapes(first_source) unless first_param.str_type? replacement_method = replacement_method(node, first_source, second_source) @@ -67,9 +64,7 @@ module RuboCop to_string_literal(first)) end - if second.empty? && first.length == 1 - remove_second_param(corrector, node, first_param) - end + remove_second_param(corrector, node, first_param) if second.empty? && first.length == 1 end end @@ -99,9 +94,7 @@ module RuboCop def offense(node, first_param, second_param) first_source, = first_source(first_param) - unless first_param.str_type? - first_source = interpret_string_escapes(first_source) - end + first_source = interpret_string_escapes(first_source) unless first_param.str_type? second_source, = *second_param message = message(node, first_source, second_source) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/times_map.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/times_map.rb similarity index 97% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/times_map.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/times_map.rb index 1a04732947..cd719da2ce 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/times_map.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/times_map.rb @@ -61,7 +61,7 @@ module RuboCop map_or_collect: map_or_collect.method_name) end - def_node_matcher :times_map_call, <<-PATTERN + def_node_matcher :times_map_call, <<~PATTERN {(block $(send (send $!nil? :times) {:map :collect}) ...) $(send (send $!nil? :times) {:map :collect} (block_pass ...))} PATTERN diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/unfreeze_string.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/unfreeze_string.rb similarity index 87% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/unfreeze_string.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/unfreeze_string.rb index 408fa959d4..eb52b1fc32 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/unfreeze_string.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/unfreeze_string.rb @@ -24,17 +24,13 @@ module RuboCop # +'something' # +'' class UnfreezeString < Cop - extend TargetRubyVersion - - minimum_target_ruby_version 2.3 - MSG = 'Use unary plus to get an unfrozen string literal.' - def_node_matcher :dup_string?, <<-PATTERN + def_node_matcher :dup_string?, <<~PATTERN (send {str dstr} :dup) PATTERN - def_node_matcher :string_new?, <<-PATTERN + def_node_matcher :string_new?, <<~PATTERN { (send (const nil? :String) :new {str dstr}) (send (const nil? :String) :new) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/uri_default_parser.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/uri_default_parser.rb similarity index 95% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/uri_default_parser.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/uri_default_parser.rb index a8aa3eb128..e0d2ac8f40 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance/uri_default_parser.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance/uri_default_parser.rb @@ -17,7 +17,7 @@ module RuboCop MSG = 'Use `%sURI::DEFAULT_PARSER` instead of ' \ '`%sURI::Parser.new`.' - def_node_matcher :uri_parser_new?, <<-PATTERN + def_node_matcher :uri_parser_new?, <<~PATTERN (send (const (const ${nil? cbase} :URI) :Parser) :new) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance_cops.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance_cops.rb similarity index 86% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance_cops.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance_cops.rb index 0d0a13d621..446357cff3 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/cop/performance_cops.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/cop/performance_cops.rb @@ -1,10 +1,15 @@ # frozen_string_literal: true +require_relative 'mixin/regexp_metacharacter' + +require_relative 'performance/bind_call' require_relative 'performance/caller' require_relative 'performance/case_when_splat' require_relative 'performance/casecmp' require_relative 'performance/compare_with_block' require_relative 'performance/count' +require_relative 'performance/delete_prefix' +require_relative 'performance/delete_suffix' require_relative 'performance/detect' require_relative 'performance/double_start_end_with' require_relative 'performance/end_with' diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance.rb similarity index 100% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance.rb diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/inject.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/inject.rb similarity index 88% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/inject.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/inject.rb index f82404dad3..e255a881a4 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/inject.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/inject.rb @@ -8,7 +8,7 @@ module RuboCop def self.defaults! path = CONFIG_DEFAULT.to_s hash = ConfigLoader.send(:load_yaml_configuration, path) - config = Config.new(hash, path) + config = Config.new(hash, path).tap(&:make_excludes_absolute) puts "configuration from #{path}" if ConfigLoader.debug? config = ConfigLoader.merge_with_default(config, path) ConfigLoader.instance_variable_set(:@default_configuration, config) diff --git a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/version.rb b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/version.rb similarity index 81% rename from Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/version.rb rename to Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/version.rb index d07d623aab..a18eaf866b 100644 --- a/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.5.2/lib/rubocop/performance/version.rb +++ b/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-performance-1.6.0/lib/rubocop/performance/version.rb @@ -3,7 +3,7 @@ module RuboCop module Performance module Version - STRING = '1.5.2' + STRING = '1.6.0' end end end