Merge pull request #14153 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-performance-1.15.1

build(deps): bump rubocop-performance from 1.15.0 to 1.15.1 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2022-11-17 14:41:00 +00:00 committed by GitHub
commit 3672890882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 52 additions and 6 deletions

View File

@ -144,7 +144,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0) unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.23.0) rubocop-ast (1.23.0)
parser (>= 3.1.1.0) parser (>= 3.1.1.0)
rubocop-performance (1.15.0) rubocop-performance (1.15.1)
rubocop (>= 1.7.0, < 2.0) rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0) rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.2) rubocop-rails (2.17.2)

View File

@ -236,6 +236,11 @@ class RuboCop::Cop::Performance::Count < ::RuboCop::Cop::Base
def autocorrect(corrector, node, selector_node, selector); end def autocorrect(corrector, node, selector_node, selector); end
def eligible_node?(node); end def eligible_node?(node); end
def negate_block_pass_as_inline_block(node); end
def negate_block_pass_reject(corrector, node); end
def negate_block_reject(corrector, node); end
def negate_expression(node); end
def negate_reject(corrector, node); end
def source_starting_at(node); end def source_starting_at(node); end
end end
@ -411,6 +416,7 @@ class RuboCop::Cop::Performance::MapCompact < ::RuboCop::Cop::Base
def invoke_method_after_map_compact_on_same_line?(compact_node, chained_method); end def invoke_method_after_map_compact_on_same_line?(compact_node, chained_method); end
def map_method_and_compact_method_on_same_line?(map_node, compact_node); end def map_method_and_compact_method_on_same_line?(map_node, compact_node); end
def remove_compact_method(corrector, map_node, compact_node, chained_method); end def remove_compact_method(corrector, map_node, compact_node, chained_method); end
def use_dot?(node); end
end end
RuboCop::Cop::Performance::MapCompact::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Performance::MapCompact::MSG = T.let(T.unsafe(nil), String)

View File

@ -105,7 +105,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.11.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.11.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.3.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.3.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.35.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.35.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.2/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.15.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.15.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.6.11/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.6.11/lib")

View File

@ -79,12 +79,11 @@ module RuboCop
def autocorrect(corrector, node, selector_node, selector) def autocorrect(corrector, node, selector_node, selector)
selector_loc = selector_node.loc.selector selector_loc = selector_node.loc.selector
return if selector == :reject
range = source_starting_at(node) { |n| n.loc.dot.begin_pos } range = source_starting_at(node) { |n| n.loc.dot.begin_pos }
corrector.remove(range) corrector.remove(range)
corrector.replace(selector_loc, 'count') corrector.replace(selector_loc, 'count')
negate_reject(corrector, node) if selector == :reject
end end
def eligible_node?(node) def eligible_node?(node)
@ -100,6 +99,43 @@ module RuboCop
range_between(begin_pos, node.source_range.end_pos) range_between(begin_pos, node.source_range.end_pos)
end end
def negate_reject(corrector, node)
if node.receiver.send_type?
negate_block_pass_reject(corrector, node)
else
negate_block_reject(corrector, node)
end
end
def negate_block_pass_reject(corrector, node)
corrector.replace(
node.receiver.loc.expression.with(begin_pos: node.receiver.loc.begin.begin_pos),
negate_block_pass_as_inline_block(node.receiver)
)
end
def negate_block_reject(corrector, node)
target =
if node.receiver.body.begin_type?
node.receiver.body.children.last
else
node.receiver.body
end
corrector.replace(target, negate_expression(target))
end
def negate_expression(node)
"!(#{node.source})"
end
def negate_block_pass_as_inline_block(node)
if node.last_argument.children.first.sym_type?
" { |element| !element.#{node.last_argument.children.first.value} }"
else
" { !#{node.last_argument.children.first.source}.call }"
end
end
end end
end end
end end

View File

@ -67,7 +67,7 @@ module RuboCop
def remove_compact_method(corrector, map_node, compact_node, chained_method) def remove_compact_method(corrector, map_node, compact_node, chained_method)
compact_method_range = compact_node.loc.selector compact_method_range = compact_node.loc.selector
if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && chained_method.dot? && if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && use_dot?(chained_method) &&
!map_method_and_compact_method_on_same_line?(map_node, compact_node) && !map_method_and_compact_method_on_same_line?(map_node, compact_node) &&
!invoke_method_after_map_compact_on_same_line?(compact_node, chained_method) !invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
compact_method_range = compact_method_with_final_newline_range(compact_method_range) compact_method_range = compact_method_with_final_newline_range(compact_method_range)
@ -78,6 +78,10 @@ module RuboCop
corrector.remove(compact_method_range) corrector.remove(compact_method_range)
end end
def use_dot?(node)
node.respond_to?(:dot?) && node.dot?
end
def map_method_and_compact_method_on_same_line?(map_node, compact_node) def map_method_and_compact_method_on_same_line?(map_node, compact_node)
compact_node.loc.selector.line == map_node.loc.selector.line compact_node.loc.selector.line == map_node.loc.selector.line
end end

View File

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