Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump rubocop-performance from 1.5.2 to 1.6.0 in /Library/Homebrew #7622

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/Gemfile.lock
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/abstract_uninstall.rb
Expand Up @@ -89,7 +89,7 @@ def uninstall_launchctl(*services, command: nil, **_)
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/audit.rb
Expand Up @@ -984,7 +984,7 @@ def audit
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/help.rb
Expand Up @@ -103,7 +103,7 @@ def comment_help(path)
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}")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/urls.rb
Expand Up @@ -230,7 +230,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
# 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
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/test/cmd/shared_examples/args_parse.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/test/rubocops/patches_spec.rb
Expand Up @@ -68,7 +68,7 @@ def patches
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:
Expand All @@ -78,7 +78,7 @@ def patches
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:
Expand Down Expand Up @@ -205,7 +205,7 @@ class Foo < Formula
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:
Expand All @@ -215,7 +215,7 @@ class Foo < Formula
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:
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/vendor/bundle/bundler/setup.rb
Expand Up @@ -12,6 +12,8 @@
$:.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"
Expand Down Expand Up @@ -59,10 +61,10 @@
$:.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"
@@ -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`.
Expand All @@ -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:
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -87,15 +103,15 @@ 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'

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'
Expand All @@ -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'
Expand Down
@@ -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
@@ -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(%<bind_arg>s%<comma>s%<call_args>s)` ' \
'instead of `bind(%<bind_arg>s).call(%<call_args>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
Expand Up @@ -24,14 +24,14 @@ class Caller < Cop
MSG_FIRST = 'Use `%<method>s(%<n>d..%<n>d).first`' \
' instead of `%<method>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)
Expand Down
Expand Up @@ -5,6 +5,8 @@ module Cop
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
Expand All @@ -21,21 +23,21 @@ class Casecmp < Cop
MSG = 'Use `%<good>s` instead of `%<bad>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? :!=}
Expand Down
Expand Up @@ -51,7 +51,7 @@ class ChainArrayAllocation < Cop
'(followed by `return array` if required) instead of chaining '\
'`%<method>s...%<second_method>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}} $...)
Expand Down
Expand Up @@ -30,14 +30,14 @@ class CompareWithBlock < Cop
'`%<compare_method>s { |%<var_a>s, %<var_b>s| %<str_a>s ' \
'<=> %<str_b>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 $...)
:<=>
Expand Down
Expand Up @@ -42,7 +42,7 @@ class Count < Cop

MSG = 'Use `count` instead of `%<selector>s...%<counter>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})
Expand Down