brew vendor-gems: commit updates.
This commit is contained in:
parent
828ac157be
commit
1ac764b1ea
@ -80,7 +80,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-1.4.1/lib
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.0.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.13.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.10.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.11.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.2.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.1/lib"
|
||||
|
||||
@ -174,6 +174,12 @@ Performance/IoReadlines:
|
||||
Enabled: false
|
||||
VersionAdded: '1.7'
|
||||
|
||||
Performance/MapCompact:
|
||||
Description: 'Use `filter_map` instead of `collection.map(&:do_something).compact`.'
|
||||
Enabled: pending
|
||||
SafeAutoCorrect: false
|
||||
VersionAdded: '1.11'
|
||||
|
||||
Performance/MethodObjectAsBlock:
|
||||
Description: 'Use block explicitly instead of block-passing a method object.'
|
||||
Reference: 'https://github.com/JuanitoFatas/fast-ruby#normal-way-to-apply-method-vs-method-code'
|
||||
@ -220,7 +226,9 @@ Performance/RedundantMerge:
|
||||
Description: 'Use Hash#[]=, rather than Hash#merge! with a single key-value pair.'
|
||||
Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code'
|
||||
Enabled: true
|
||||
Safe: false
|
||||
VersionAdded: '0.36'
|
||||
VersionChanged: '1.11'
|
||||
# Max number of key-value pairs to consider an offense
|
||||
MaxKeyValuePairs: 2
|
||||
|
||||
@ -258,6 +266,11 @@ Performance/ReverseFirst:
|
||||
Enabled: 'pending'
|
||||
VersionAdded: '1.7'
|
||||
|
||||
Performance/SelectMap:
|
||||
Description: 'Use `filter_map` instead of `ary.select(&:foo).map(&:bar)`.'
|
||||
Enabled: false
|
||||
VersionAdded: '1.11'
|
||||
|
||||
Performance/Size:
|
||||
Description: >-
|
||||
Use `size` instead of `count` for counting
|
||||
@ -0,0 +1,7 @@
|
||||
#
|
||||
# Configuration for obsoletion.
|
||||
#
|
||||
# See: https://docs.rubocop.org/rubocop/extensions.html#config-obsoletions
|
||||
#
|
||||
extracted:
|
||||
Performance/*: ~
|
||||
@ -63,6 +63,8 @@ module RuboCop
|
||||
|
||||
def on_send(node)
|
||||
chain_array_allocation?(node) do |fm, sm|
|
||||
return if node.each_descendant(:send).any? { |descendant| descendant.method?(:lazy) }
|
||||
|
||||
range = range_between(node.loc.dot.begin_pos, node.source_range.end_pos)
|
||||
|
||||
add_offense(range, message: format(MSG, method: fm, second_method: sm))
|
||||
@ -3,7 +3,8 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Performance
|
||||
# This cop is used to identify usages of
|
||||
# This cop is used to identify usages of `map { ... }.flatten` and
|
||||
# change them to use `flat_map { ... }` instead.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Performance
|
||||
# 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`.
|
||||
#
|
||||
# [source,ruby]
|
||||
# ----
|
||||
# [true, false, nil].compact #=> [true, false]
|
||||
# [true, false, nil].filter_map(&:itself) #=> [true]
|
||||
# ----
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# ary.map(&:foo).compact
|
||||
# ary.collect(&:foo).compact
|
||||
#
|
||||
# # good
|
||||
# ary.filter_map(&:foo)
|
||||
# ary.map(&:foo).compact!
|
||||
#
|
||||
class MapCompact < Base
|
||||
include RangeHelp
|
||||
extend AutoCorrector
|
||||
extend TargetRubyVersion
|
||||
|
||||
MSG = 'Use `filter_map` instead.'
|
||||
RESTRICT_ON_SEND = %i[compact].freeze
|
||||
|
||||
minimum_target_ruby_version 2.7
|
||||
|
||||
def_node_matcher :map_compact, <<~PATTERN
|
||||
{
|
||||
(send
|
||||
$(send _ {:map :collect}
|
||||
(block_pass
|
||||
(sym _))) _)
|
||||
(send
|
||||
(block
|
||||
$(send _ {:map :collect})
|
||||
(args ...) _) _)
|
||||
}
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
return unless (map_node = map_compact(node))
|
||||
|
||||
compact_loc = node.loc
|
||||
range = range_between(map_node.loc.selector.begin_pos, compact_loc.selector.end_pos)
|
||||
|
||||
add_offense(range) do |corrector|
|
||||
corrector.replace(map_node.loc.selector, 'filter_map')
|
||||
corrector.remove(compact_loc.dot)
|
||||
corrector.remove(compact_loc.selector)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -8,6 +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.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# hash.merge!(a: 1)
|
||||
@ -0,0 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Performance
|
||||
# In Ruby 2.7, `Enumerable#filter_map` has been added.
|
||||
#
|
||||
# This cop identifies places where `select.map` can be replaced by `filter_map`.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# ary.select(&:foo).map(&:bar)
|
||||
# ary.filter(&:foo).map(&:bar)
|
||||
#
|
||||
# # good
|
||||
# ary.filter_map { |o| o.bar if o.foo }
|
||||
#
|
||||
class SelectMap < Base
|
||||
include RangeHelp
|
||||
extend TargetRubyVersion
|
||||
|
||||
minimum_target_ruby_version 2.7
|
||||
|
||||
MSG = 'Use `filter_map` instead of `%<method_name>s.map`.'
|
||||
RESTRICT_ON_SEND = %i[select filter].freeze
|
||||
|
||||
def_node_matcher :bad_method?, <<~PATTERN
|
||||
(send nil? :bad_method ...)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
return if (first_argument = node.first_argument) && !first_argument.block_pass_type?
|
||||
return unless (send_node = map_method_candidate(node))
|
||||
return unless send_node.method?(:map)
|
||||
|
||||
map_method = send_node.parent&.block_type? ? send_node.parent : send_node
|
||||
|
||||
range = offense_range(node, map_method)
|
||||
add_offense(range, message: format(MSG, method_name: node.method_name))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def map_method_candidate(node)
|
||||
return unless (parent = node.parent)
|
||||
|
||||
if parent.block_type? && parent.parent&.send_type?
|
||||
parent.parent
|
||||
elsif parent.send_type?
|
||||
parent
|
||||
end
|
||||
end
|
||||
|
||||
def offense_range(node, map_method)
|
||||
range_between(node.loc.selector.begin_pos, map_method.loc.expression.end_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -23,6 +23,7 @@ require_relative 'performance/end_with'
|
||||
require_relative 'performance/fixed_size'
|
||||
require_relative 'performance/flat_map'
|
||||
require_relative 'performance/inefficient_hash_search'
|
||||
require_relative 'performance/map_compact'
|
||||
require_relative 'performance/method_object_as_block'
|
||||
require_relative 'performance/open_struct'
|
||||
require_relative 'performance/range_include'
|
||||
@ -37,6 +38,7 @@ require_relative 'performance/redundant_string_chars'
|
||||
require_relative 'performance/regexp_match'
|
||||
require_relative 'performance/reverse_each'
|
||||
require_relative 'performance/reverse_first'
|
||||
require_relative 'performance/select_map'
|
||||
require_relative 'performance/size'
|
||||
require_relative 'performance/sort_reverse'
|
||||
require_relative 'performance/squeeze'
|
||||
@ -8,5 +8,7 @@ module RuboCop
|
||||
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
||||
|
||||
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
||||
|
||||
::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join('config', 'obsoletion.yml')
|
||||
end
|
||||
end
|
||||
@ -4,7 +4,7 @@ module RuboCop
|
||||
module Performance
|
||||
# This module holds the RuboCop Performance version information.
|
||||
module Version
|
||||
STRING = '1.10.2'
|
||||
STRING = '1.11.0'
|
||||
|
||||
def self.document_version
|
||||
STRING.match('\d+\.\d+').to_s
|
||||
Loading…
x
Reference in New Issue
Block a user