Merge pull request #12365 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-performance-1.12.0

build(deps): bump rubocop-performance from 1.11.5 to 1.12.0 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2021-11-02 11:41:10 +00:00 committed by GitHub
commit 5c44aca2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 180 additions and 68 deletions

View File

@ -135,7 +135,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.12.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.5)
rubocop-performance (1.12.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.12.4)

View File

@ -26,7 +26,7 @@ module Cask
return to_enum unless block
Tap.flat_map(&:cask_files).each do |f|
block.call CaskLoader::FromTapPathLoader.new(f).load(config: nil)
yield CaskLoader::FromTapPathLoader.new(f).load(config: nil)
rescue CaskUnreadableError => e
opoo e.message
end

View File

@ -1674,9 +1674,9 @@ class Formula
end
# @private
def self.each(&block)
def self.each(&_block)
files.each do |file|
block.call Formulary.factory(file)
yield Formulary.factory(file)
rescue FormulaUnavailableError, FormulaUnreadableError => e
# Don't let one broken formula break commands. But do complain.
onoe "Failed to import: #{file}"

View File

@ -50,7 +50,7 @@ module Homebrew
yaml = YAML.safe_load(content)
return [] if yaml.blank?
return Strategy.handle_block_return(block.call(yaml)) if block
return Strategy.handle_block_return(yield(yaml)) if block
version = yaml["version"]
version.present? ? [version] : []

View File

@ -68,7 +68,7 @@ module Homebrew
).returns(T::Array[String])
}
def self.versions_from_items(items, &block)
return Strategy.handle_block_return(block.call(items)) if block
return Strategy.handle_block_return(yield(items)) if block
items.map do |_key, item|
item.bundle_version.nice_version

View File

@ -93,7 +93,7 @@ module Homebrew
).returns(T::Array[String])
}
def self.versions_from_tags(tags, regex = nil, &block)
return Strategy.handle_block_return(block.call(tags, regex || DEFAULT_REGEX)) if block
return Strategy.handle_block_return(yield(tags, regex || DEFAULT_REGEX)) if block
tags_only_debian = tags.all? { |tag| tag.start_with?("debian/") }

View File

@ -53,7 +53,7 @@ module Homebrew
).returns(T::Array[String])
}
def self.versions_from_headers(headers, regex = nil, &block)
return Strategy.handle_block_return(block.call(headers, regex)) if block
return Strategy.handle_block_return(yield(headers, regex)) if block
DEFAULT_HEADERS_TO_CHECK.map do |header_name|
header_value = headers[header_name]

View File

@ -57,7 +57,7 @@ module Homebrew
).returns(T::Array[String])
}
def self.versions_from_content(content, regex, &block)
return Strategy.handle_block_return(block.call(content, regex)) if block
return Strategy.handle_block_return(yield(content, regex)) if block
return [] if regex.blank?
content.scan(regex).map do |match|

View File

@ -157,7 +157,7 @@ module Homebrew
item = item_from_content(content)
return [] if item.blank?
return Strategy.handle_block_return(block.call(item)) if block
return Strategy.handle_block_return(yield(item)) if block
version = item.bundle_version&.nice_version
version.present? ? [version] : []

View File

@ -1,9 +1,9 @@
# typed: true
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `rubocop-performance` gem.
# Please instead update this file by running `bin/tapioca gem rubocop-performance`.
# typed: true
module RuboCop; end
module RuboCop::Cop; end
module RuboCop::Cop::Performance; end
@ -202,6 +202,16 @@ end
RuboCop::Cop::Performance::CompareWithBlock::MSG = T.let(T.unsafe(nil), String)
class RuboCop::Cop::Performance::ConcurrentMonotonicTime < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector
def concurrent_monotonic_time?(param0 = T.unsafe(nil)); end
def on_send(node); end
end
RuboCop::Cop::Performance::ConcurrentMonotonicTime::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Performance::ConcurrentMonotonicTime::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Performance::ConstantRegexp < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector
@ -236,7 +246,6 @@ RuboCop::Cop::Performance::Count::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Performance::DeletePrefix < ::RuboCop::Cop::Base
include ::RuboCop::Cop::RegexpMetacharacter
extend ::RuboCop::Cop::AutoCorrector
extend ::RuboCop::Cop::TargetRubyVersion
def delete_prefix_candidate?(param0 = T.unsafe(nil)); end
def on_send(node); end
@ -249,7 +258,6 @@ RuboCop::Cop::Performance::DeletePrefix::RESTRICT_ON_SEND = T.let(T.unsafe(nil),
class RuboCop::Cop::Performance::DeleteSuffix < ::RuboCop::Cop::Base
include ::RuboCop::Cop::RegexpMetacharacter
extend ::RuboCop::Cop::AutoCorrector
extend ::RuboCop::Cop::TargetRubyVersion
def delete_suffix_candidate?(param0 = T.unsafe(nil)); end
def on_send(node); end
@ -437,6 +445,7 @@ class RuboCop::Cop::Performance::RedundantBlockCall < ::RuboCop::Cop::Base
def blockarg_calls(param0, param1); end
def blockarg_def(param0 = T.unsafe(nil)); end
def on_def(node); end
def on_defs(node); end
private
@ -454,7 +463,6 @@ RuboCop::Cop::Performance::RedundantBlockCall::YIELD = T.let(T.unsafe(nil), Stri
class RuboCop::Cop::Performance::RedundantEqualityComparisonBlock < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector
extend ::RuboCop::Cop::TargetRubyVersion
def on_block(node); end

View File

@ -659,7 +659,7 @@ class Tap
TAP_DIRECTORY.subdirs.each do |user|
user.subdirs.each do |repo|
block.call fetch(user.basename.to_s, repo.basename.to_s)
yield fetch(user.basename.to_s, repo.basename.to_s)
end
end
end

View File

@ -87,7 +87,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-1.12.0/li
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.1.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.22.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.11.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.12.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.12.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.2/lib"

View File

@ -76,6 +76,12 @@ Performance/CompareWithBlock:
Enabled: true
VersionAdded: '0.46'
Performance/ConcurrentMonotonicTime:
Description: 'Use `Process.clock_gettime(Process::CLOCK_MONOTONIC)` instead of `Concurrent.monotonic_time`.'
Reference: 'https://github.com/rails/rails/pull/43502'
Enabled: pending
VersionAdded: '1.12'
Performance/ConstantRegexp:
Description: 'Finds regular expressions with dynamic components that are all constants.'
Enabled: pending
@ -309,9 +315,9 @@ Performance/StartWith:
Performance/StringInclude:
Description: 'Use `String#include?` instead of a regex match with literal-only pattern.'
Enabled: 'pending'
AutoCorrect: false
SafeAutoCorrect: false
VersionAdded: '1.7'
VersionChanged: '1.12'
Performance/StringReplacement:
Description: >-

View File

@ -6,6 +6,10 @@ module RuboCop
# This cop is used to identify usages of `ancestors.include?` and
# change them to use `<=` instead.
#
# @safety
# This cop is unsafe because it can't tell whether the receiver is a class or an object.
# e.g. the false positive was for `Nokogiri::XML::Node#ancestors`.
#
# @example
# # bad
# A.ancestors.include?(B)

View File

@ -7,7 +7,9 @@ module RuboCop
# can be replaced by `Array#take` and `Array#drop`.
# This cop was created due to a mistake in microbenchmark and hence is disabled by default.
# Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
# This cop is also unsafe for string slices because strings do not have `#take` and `#drop` methods.
#
# @safety
# This cop is unsafe for string slices because strings do not have `#take` and `#drop` methods.
#
# @example
# # bad

View File

@ -17,11 +17,13 @@ module RuboCop
# this defining a higher level when condition to override a condition
# that is inside of the splat expansion.
#
# This is not a guaranteed performance improvement. If the data being
# processed by the `case` condition is normalized in a manner that favors
# hitting a condition in the splat expansion, it is possible that
# moving the splat condition to the end will use more memory,
# and run slightly slower.
# @safety
# This cop is not unsafe auto-correction because it is not a guaranteed
# performance improvement. If the data being processed by the `case` condition is
# normalized in a manner that favors hitting a condition in the splat expansion,
# it is possible that moving the splat condition to the end will use more memory,
# and run slightly slower.
# See for more details: https://github.com/rubocop/rubocop/pull/6163
#
# @example
# # bad

View File

@ -5,8 +5,10 @@ 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.
#
# @safety
# This cop is unsafe because `String#casecmp` and `String#casecmp?` behave
# differently when using Non-ASCII characters.
#
# @example
# # bad

View File

@ -0,0 +1,42 @@
# frozen_string_literal: true
module RuboCop
module Cop
module Performance
# This cop identifies places where `Concurrent.monotonic_time`
# can be replaced by `Process.clock_gettime(Process::CLOCK_MONOTONIC)`.
#
# @example
#
# # bad
# Concurrent.monotonic_time
#
# # good
# Process.clock_gettime(Process::CLOCK_MONOTONIC)
#
class ConcurrentMonotonicTime < Base
extend AutoCorrector
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
RESTRICT_ON_SEND = %i[monotonic_time].freeze
def_node_matcher :concurrent_monotonic_time?, <<~PATTERN
(send
(const {nil? cbase} :Concurrent) :monotonic_time ...)
PATTERN
def on_send(node)
return unless concurrent_monotonic_time?(node)
optional_unit_parameter = ", #{node.first_argument.source}" if node.first_argument
prefer = "Process.clock_gettime(Process::CLOCK_MONOTONIC#{optional_unit_parameter})"
message = format(MSG, prefer: prefer, current: node.source)
add_offense(node, message: message) do |corrector|
corrector.replace(node, prefer)
end
end
end
end
end
end

View File

@ -7,6 +7,28 @@ module RuboCop
# follow calls to `select`, `find_all`, `filter` or `reject`. Querying logic can instead be
# passed to the `count` call.
#
# @safety
# This cop is unsafe because it has known compatibility issues with `ActiveRecord` and other
# frameworks. ActiveRecord's `count` ignores the block that is passed to it.
# `ActiveRecord` will ignore the block that is passed to `count`.
# Other methods, such as `select`, will convert the association to an
# array and then run the block on the array. A simple work around to
# make `count` work with a block is to call `to_a.count {...}`.
#
# For example:
#
# [source,ruby]
# ----
# `Model.where(id: [1, 2, 3]).select { |m| m.method == true }.size`
# ----
#
# becomes:
#
# [source,ruby]
# ----
# `Model.where(id: [1, 2, 3]).to_a.count { |m| m.method == true }`
# ----
#
# @example
# # bad
# [1, 2, 3].select { |e| e > 2 }.size
@ -24,19 +46,6 @@ module RuboCop
# [1, 2, 3].count { |e| e < 2 && e.even? }
# Model.select('field AS field_one').count
# Model.select(:value).count
#
# `ActiveRecord` compatibility:
# `ActiveRecord` will ignore the block that is passed to `count`.
# Other methods, such as `select`, will convert the association to an
# array and then run the block on the array. A simple work around to
# make `count` work with a block is to call `to_a.count {...}`.
#
# Example:
# `Model.where(id: [1, 2, 3]).select { |m| m.method == true }.size`
#
# becomes:
#
# `Model.where(id: [1, 2, 3]).to_a.count { |m| m.method == true }`
class Count < Base
include RangeHelp
extend AutoCorrector

View File

@ -7,7 +7,6 @@ module RuboCop
#
# This cop identifies places where `gsub(/\Aprefix/, '')` and `sub(/\Aprefix/, '')`
# can be replaced by `delete_prefix('prefix')`.
# It is marked as unsafe by default because `Pathname` has `sub` but not `delete_prefix`.
#
# This cop has `SafeMultiline` configuration option that `true` by default because
# `^prefix` is unsafe as it will behave incompatible with `delete_prefix`
@ -15,6 +14,9 @@ module RuboCop
#
# The `delete_prefix('prefix')` method is faster than `gsub(/\Aprefix/, '')`.
#
# @safety
# This cop is unsafe because `Pathname` has `sub` but not `delete_prefix`.
#
# @example
#
# # bad
@ -47,9 +49,6 @@ module RuboCop
class DeletePrefix < Base
include RegexpMetacharacter
extend AutoCorrector
extend TargetRubyVersion
minimum_target_ruby_version 2.5
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
RESTRICT_ON_SEND = %i[gsub gsub! sub sub!].freeze

View File

@ -7,7 +7,6 @@ module RuboCop
#
# This cop identifies places where `gsub(/suffix\z/, '')` and `sub(/suffix\z/, '')`
# can be replaced by `delete_suffix('suffix')`.
# It is marked as unsafe by default because `Pathname` has `sub` but not `delete_suffix`.
#
# This cop has `SafeMultiline` configuration option that `true` by default because
# `suffix$` is unsafe as it will behave incompatible with `delete_suffix?`
@ -15,6 +14,9 @@ module RuboCop
#
# The `delete_suffix('suffix')` method is faster than `gsub(/suffix\z/, '')`.
#
# @safety
# This cop is unsafe because `Pathname` has `sub` but not `delete_suffix`.
#
# @example
#
# # bad
@ -47,9 +49,6 @@ module RuboCop
class DeleteSuffix < Base
include RegexpMetacharacter
extend AutoCorrector
extend TargetRubyVersion
minimum_target_ruby_version 2.5
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
RESTRICT_ON_SEND = %i[gsub gsub! sub sub!].freeze

View File

@ -7,6 +7,11 @@ module RuboCop
# chained to `select`, `find_all` or `filter` and change them to use
# `detect` instead.
#
# @safety
# This cop is unsafe because is has known compatibility issues with `ActiveRecord` and other
# frameworks. `ActiveRecord` does not implement a `detect` method and `find` has its own
# meaning. Correcting `ActiveRecord` methods with this cop should be considered unsafe.
#
# @example
# # bad
# [].select { |item| true }.first
@ -90,7 +95,7 @@ module RuboCop
end
def replacement(method, index)
if method == :last || method == :[] && index == -1
if method == :last || (method == :[] && index == -1)
"reverse.#{preferred_method}"
else
preferred_method

View File

@ -9,6 +9,11 @@ module RuboCop
# `end$` is unsafe as it will behave incompatible with `end_with?`
# for receiver is multiline string.
#
# @safety
# This will change to a new method call which isn't guaranteed to be on the
# object. Switching these methods has to be done with knowledge of the types
# of the variables which rubocop doesn't have.
#
# @example
# # bad
# 'abc'.match?(/bc\Z/)

View File

@ -15,6 +15,9 @@ module RuboCop
# both perform an O(n) search through all of the values, calling `values`
# allocates a new array while using `value?` does not.
#
# @safety
# This cop is unsafe because it can't tell whether the receiver is a hash object.
#
# @example
# # bad
# { a: 1, b: 2 }.keys.include?(:a)

View File

@ -6,8 +6,10 @@ module RuboCop
# In Ruby 2.7, `Enumerable#filter_map` has been added.
#
# This cop identifies places where `map { ... }.compact` can be replaced by `filter_map`.
# It is marked as unsafe auto-correction by default because `map { ... }.compact`
# that is not compatible with `filter_map`.
#
# @safety
# This cop's autocorrection is unsafe because `map { ... }.compact` that is not
# compatible with `filter_map`.
#
# [source,ruby]
# ----

View File

@ -11,6 +11,10 @@ module RuboCop
# especially in case of single-threaded
# applications with multiple `OpenStruct` instantiations.
#
# @safety
# This cop is unsafe because `OpenStruct.new` and `Struct.new`
# are not equivalent.
#
# @example
# # bad
# class MyClass

View File

@ -9,8 +9,9 @@ module RuboCop
# end points of the `Range`. In a great majority of cases, this is what
# is wanted.
#
# This cop is `Safe: false` by default because `Range#include?` (or `Range#member?`) and
# `Range#cover?` are not equivalent behaviour.
# @safety
# This cop is unsafe because `Range#include?` (or `Range#member?`) and `Range#cover?`
# are not equivalent behaviour.
#
# @example
# # bad

View File

@ -9,8 +9,9 @@ module RuboCop
# By default, `Object#===` behaves the same as `Object#==`, but this
# behavior is appropriately overridden in subclass. For example,
# `Range#===` returns `true` when argument is within the range.
# Therefore, It is marked as unsafe by default because `===` and `==`
# do not always behave the same.
#
# @safety
# This cop is unsafe because `===` and `==` do not always behave the same.
#
# @example
# # bad
@ -24,9 +25,6 @@ module RuboCop
#
class RedundantEqualityComparisonBlock < Base
extend AutoCorrector
extend TargetRubyVersion
minimum_target_ruby_version 2.5
MSG = 'Use `%<prefer>s` instead of block.'

View File

@ -8,8 +8,9 @@ module RuboCop
# You can set the maximum number of key-value pairs to consider
# an offense with `MaxKeyValuePairs`.
#
# This cop is marked as unsafe because RuboCop cannot determine if the
# receiver of `merge!` is actually a hash or not.
# @safety
# This cop is unsafe because RuboCop cannot determine if the
# receiver of `merge!` is actually a hash or not.
#
# @example
# # bad
@ -91,7 +92,7 @@ module RuboCop
end
def non_redundant_pairs?(receiver, pairs)
pairs.size > 1 && !receiver.pure? || pairs.size > max_key_value_pairs
(pairs.size > 1 && !receiver.pure?) || pairs.size > max_key_value_pairs
end
def kwsplat_used?(pairs)

View File

@ -9,6 +9,11 @@ module RuboCop
# `^start` is unsafe as it will behave incompatible with `start_with?`
# for receiver is multiline string.
#
# @safety
# This will change to a new method call which isn't guaranteed to be on the
# object. Switching these methods has to be done with knowledge of the types
# of the variables which rubocop doesn't have.
#
# @example
# # bad
# 'abc'.match?(/\Aab/)

View File

@ -6,7 +6,8 @@ module RuboCop
# This cop identifies unnecessary use of a regex where
# `String#include?` would suffice.
#
# This cop's offenses are not safe to auto-correct if a receiver is nil.
# @safety
# This cop's offenses are not safe to auto-correct if a receiver is nil.
#
# @example
# # bad

View File

@ -156,7 +156,7 @@ module RuboCop
end
def sum_method_range(node)
range_between(node.loc.selector.begin_pos, node.loc.end.end_pos)
range_between(node.loc.selector.begin_pos, node.loc.expression.end_pos)
end
def sum_map_range(map, sum)

View File

@ -7,6 +7,18 @@ module RuboCop
# In most cases such calls can be replaced
# with an explicit array creation.
#
# @safety
# This cop's autocorrection is unsafe because `Integer#times` does nothing if receiver is 0
# or less. However, `Array.new` raises an error if argument is less than 0.
#
# For example:
#
# [source,ruby]
# ----
# -1.times{} # does nothing
# Array.new(-1) # ArgumentError: negative array size
# ----
#
# @example
# # bad
# 9.times.map do |i|

View File

@ -7,11 +7,11 @@ module RuboCop
# literal instead of `String#dup` and `String.new`.
# Unary plus operator is faster than `String#dup`.
#
# NOTE: `String.new` (without operator) is not exactly the same as `+''`.
# These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`.
# However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
# Therefore, auto-correction is unsafe.
# So, if you expect `ASCII-8BIT` encoding, disable this cop.
# @safety
# This cop's autocorrection is unsafe because `String.new` (without operator) is not
# exactly the same as `+''`. These differ in encoding. `String.new.encoding` is always
# `ASCII-8BIT`. However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
# if you expect `ASCII-8BIT` encoding, disable this cop.
#
# @example
# # bad

View File

@ -13,6 +13,7 @@ require_relative 'performance/case_when_splat'
require_relative 'performance/casecmp'
require_relative 'performance/collection_literal_in_loop'
require_relative 'performance/compare_with_block'
require_relative 'performance/concurrent_monotonic_time'
require_relative 'performance/constant_regexp'
require_relative 'performance/count'
require_relative 'performance/delete_prefix'

View File

@ -4,7 +4,7 @@ module RuboCop
module Performance
# This module holds the RuboCop Performance version information.
module Version
STRING = '1.11.5'
STRING = '1.12.0'
def self.document_version
STRING.match('\d+\.\d+').to_s