brew vendor-gems: commit updates.
This commit is contained in:
parent
3a371a43d7
commit
dd88369208
@ -87,7 +87,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-1.21.0/li
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11.0/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.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.35.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.35.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.14.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.15.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.16.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.16.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.12.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.12.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.11/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.11/lib"
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# This is the default configuration file.
|
# This is the default configuration file.
|
||||||
|
|
||||||
|
Performance:
|
||||||
|
Enabled: true
|
||||||
|
DocumentationBaseURL: https://docs.rubocop.org/rubocop-performance
|
||||||
|
|
||||||
Performance/AncestorsInclude:
|
Performance/AncestorsInclude:
|
||||||
Description: 'Use `A <= B` instead of `A.ancestors.include?(B)`.'
|
Description: 'Use `A <= B` instead of `A.ancestors.include?(B)`.'
|
||||||
Reference: 'https://github.com/JuanitoFatas/fast-ruby#ancestorsinclude-vs--code'
|
Reference: 'https://github.com/JuanitoFatas/fast-ruby#ancestorsinclude-vs--code'
|
||||||
@ -14,6 +14,13 @@ module RuboCop
|
|||||||
$send)
|
$send)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :sort_with_numblock?, <<~PATTERN
|
||||||
|
(numblock
|
||||||
|
$(send _ :sort)
|
||||||
|
$_arg_count
|
||||||
|
$send)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :replaceable_body?, <<~PATTERN
|
def_node_matcher :replaceable_body?, <<~PATTERN
|
||||||
(send (lvar %1) :<=> (lvar %2))
|
(send (lvar %1) :<=> (lvar %2))
|
||||||
PATTERN
|
PATTERN
|
||||||
@ -41,11 +41,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
elsif (numeric_to_d = to_d?(node))
|
elsif (numeric_to_d = to_d?(node))
|
||||||
add_offense(numeric_to_d.source_range) do |corrector|
|
add_offense(numeric_to_d.source_range) do |corrector|
|
||||||
big_decimal_args = node
|
big_decimal_args = node.arguments.map(&:source).unshift("'#{numeric_to_d.source}'").join(', ')
|
||||||
.arguments
|
|
||||||
.map(&:source)
|
|
||||||
.unshift("'#{numeric_to_d.source}'")
|
|
||||||
.join(', ')
|
|
||||||
|
|
||||||
corrector.replace(node, "BigDecimal(#{big_decimal_args})")
|
corrector.replace(node, "BigDecimal(#{big_decimal_args})")
|
||||||
end
|
end
|
||||||
@ -26,8 +26,7 @@ module RuboCop
|
|||||||
|
|
||||||
minimum_target_ruby_version 2.7
|
minimum_target_ruby_version 2.7
|
||||||
|
|
||||||
MSG = 'Use `bind_call(%<bind_arg>s%<comma>s%<call_args>s)` ' \
|
MSG = 'Use `bind_call(%<bind_arg>s%<comma>s%<call_args>s)` instead of `bind(%<bind_arg>s).call(%<call_args>s)`.'
|
||||||
'instead of `bind(%<bind_arg>s).call(%<call_args>s)`.'
|
|
||||||
RESTRICT_ON_SEND = %i[call].freeze
|
RESTRICT_ON_SEND = %i[call].freeze
|
||||||
|
|
||||||
def_node_matcher :bind_with_call_method?, <<~PATTERN
|
def_node_matcher :bind_with_call_method?, <<~PATTERN
|
||||||
@ -99,8 +99,7 @@ module RuboCop
|
|||||||
|
|
||||||
def inline_fix_branch(corrector, when_node)
|
def inline_fix_branch(corrector, when_node)
|
||||||
conditions = when_node.conditions
|
conditions = when_node.conditions
|
||||||
range = range_between(conditions[0].loc.expression.begin_pos,
|
range = range_between(conditions[0].loc.expression.begin_pos, conditions[-1].loc.expression.end_pos)
|
||||||
conditions[-1].loc.expression.end_pos)
|
|
||||||
|
|
||||||
corrector.replace(range, replacement(conditions))
|
corrector.replace(range, replacement(conditions))
|
||||||
end
|
end
|
||||||
@ -111,8 +110,7 @@ module RuboCop
|
|||||||
return if when_branches.one?
|
return if when_branches.one?
|
||||||
|
|
||||||
corrector.remove(when_branch_range(when_node))
|
corrector.remove(when_branch_range(when_node))
|
||||||
corrector.insert_after(when_branches.last.source_range,
|
corrector.insert_after(when_branches.last.source_range, reordering_correction(when_node))
|
||||||
reordering_correction(when_node))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reordering_correction(when_node)
|
def reordering_correction(when_node)
|
||||||
@ -126,11 +124,9 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def when_branch_range(when_node)
|
def when_branch_range(when_node)
|
||||||
next_branch =
|
next_branch = when_node.parent.when_branches[when_node.branch_index + 1]
|
||||||
when_node.parent.when_branches[when_node.branch_index + 1]
|
|
||||||
|
|
||||||
range_between(when_node.source_range.begin_pos,
|
range_between(when_node.source_range.begin_pos, next_branch.source_range.begin_pos)
|
||||||
next_branch.source_range.begin_pos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_condition_with_then(node, new_condition)
|
def new_condition_with_then(node, new_condition)
|
||||||
@ -162,13 +158,11 @@ module RuboCop
|
|||||||
def non_splat?(condition)
|
def non_splat?(condition)
|
||||||
variable, = *condition
|
variable, = *condition
|
||||||
|
|
||||||
(condition.splat_type? && variable.array_type?) ||
|
(condition.splat_type? && variable.array_type?) || !condition.splat_type?
|
||||||
!condition.splat_type?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_reorder?(when_node)
|
def needs_reorder?(when_node)
|
||||||
following_branches =
|
following_branches = when_node.parent.when_branches[(when_node.branch_index + 1)..]
|
||||||
when_node.parent.when_branches[(when_node.branch_index + 1)..]
|
|
||||||
|
|
||||||
following_branches.any? do |when_branch|
|
following_branches.any? do |when_branch|
|
||||||
when_branch.conditions.any? do |condition|
|
when_branch.conditions.any? do |condition|
|
||||||
@ -104,9 +104,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def loop?(ancestor, node)
|
def loop?(ancestor, node)
|
||||||
keyword_loop?(ancestor.type) ||
|
keyword_loop?(ancestor.type) || kernel_loop?(ancestor) || node_within_enumerable_loop?(node, ancestor)
|
||||||
kernel_loop?(ancestor) ||
|
|
||||||
node_within_enumerable_loop?(node, ancestor)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def keyword_loop?(type)
|
def keyword_loop?(type)
|
||||||
@ -39,9 +39,7 @@ module RuboCop
|
|||||||
MSG = 'Extract this regexp into a constant, memoize it, or append an `/o` option to its options.'
|
MSG = 'Extract this regexp into a constant, memoize it, or append an `/o` option to its options.'
|
||||||
|
|
||||||
def on_regexp(node)
|
def on_regexp(node)
|
||||||
return if within_allowed_assignment?(node) ||
|
return if within_allowed_assignment?(node) || !include_interpolated_const?(node) || node.single_interpolation?
|
||||||
!include_interpolated_const?(node) ||
|
|
||||||
node.single_interpolation?
|
|
||||||
|
|
||||||
add_offense(node) do |corrector|
|
add_offense(node) do |corrector|
|
||||||
corrector.insert_after(node, 'o')
|
corrector.insert_after(node, 'o')
|
||||||
@ -41,8 +41,7 @@ module RuboCop
|
|||||||
class DoubleStartEndWith < Base
|
class DoubleStartEndWith < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `%<receiver>s.%<method>s(%<combined_args>s)` ' \
|
MSG = 'Use `%<receiver>s.%<method>s(%<combined_args>s)` instead of `%<original_code>s`.'
|
||||||
'instead of `%<original_code>s`.'
|
|
||||||
|
|
||||||
def on_or(node)
|
def on_or(node)
|
||||||
receiver, method, first_call_args, second_call_args = process_source(node)
|
receiver, method, first_call_args, second_call_args = process_source(node)
|
||||||
@ -50,8 +50,7 @@ module RuboCop
|
|||||||
include RegexpMetacharacter
|
include RegexpMetacharacter
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `String#end_with?` instead of a regex match anchored to ' \
|
MSG = 'Use `String#end_with?` instead of a regex match anchored to the end of the string.'
|
||||||
'the end of the string.'
|
|
||||||
RESTRICT_ON_SEND = %i[match =~ match?].freeze
|
RESTRICT_ON_SEND = %i[match =~ match?].freeze
|
||||||
|
|
||||||
def_node_matcher :redundant_regex?, <<~PATTERN
|
def_node_matcher :redundant_regex?, <<~PATTERN
|
||||||
@ -83,9 +83,7 @@ module RuboCop
|
|||||||
|
|
||||||
def use_long_method
|
def use_long_method
|
||||||
preferred_config = config.for_all_cops['Style/PreferredHashMethods']
|
preferred_config = config.for_all_cops['Style/PreferredHashMethods']
|
||||||
preferred_config &&
|
preferred_config && preferred_config['EnforcedStyle'] == 'long' && preferred_config['Enabled']
|
||||||
preferred_config['EnforcedStyle'] == 'long' &&
|
|
||||||
preferred_config['Enabled']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocorrect_argument(node)
|
def autocorrect_argument(node)
|
||||||
@ -32,8 +32,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class OpenStruct < Base
|
class OpenStruct < Base
|
||||||
MSG = 'Consider using `Struct` over `OpenStruct` ' \
|
MSG = 'Consider using `Struct` over `OpenStruct` to optimize the performance.'
|
||||||
'to optimize the performance.'
|
|
||||||
RESTRICT_ON_SEND = %i[new].freeze
|
RESTRICT_ON_SEND = %i[new].freeze
|
||||||
|
|
||||||
def_node_matcher :open_struct, <<~PATTERN
|
def_node_matcher :open_struct, <<~PATTERN
|
||||||
@ -20,8 +20,7 @@ module RuboCop
|
|||||||
class RedundantMatch < Base
|
class RedundantMatch < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `=~` in places where the `MatchData` returned by ' \
|
MSG = 'Use `=~` in places where the `MatchData` returned by `#match` will not be used.'
|
||||||
'`#match` will not be used.'
|
|
||||||
RESTRICT_ON_SEND = %i[match].freeze
|
RESTRICT_ON_SEND = %i[match].freeze
|
||||||
|
|
||||||
# 'match' is a fairly generic name, so we don't flag it unless we see
|
# 'match' is a fairly generic name, so we don't flag it unless we see
|
||||||
@ -41,21 +40,23 @@ module RuboCop
|
|||||||
!(node.parent && node.parent.block_type?)
|
!(node.parent && node.parent.block_type?)
|
||||||
|
|
||||||
add_offense(node) do |corrector|
|
add_offense(node) do |corrector|
|
||||||
autocorrect(corrector, node)
|
autocorrect(corrector, node) if autocorrectable?(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def autocorrect(corrector, node)
|
def autocorrect(corrector, node)
|
||||||
# Regexp#match can take a second argument, but this cop doesn't
|
|
||||||
# register an offense in that case
|
|
||||||
return unless node.first_argument.regexp_type?
|
|
||||||
|
|
||||||
new_source = "#{node.receiver.source} =~ #{node.first_argument.source}"
|
new_source = "#{node.receiver.source} =~ #{node.first_argument.source}"
|
||||||
|
|
||||||
corrector.replace(node.source_range, new_source)
|
corrector.replace(node.source_range, new_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autocorrectable?(node)
|
||||||
|
# Regexp#match can take a second argument, but this cop doesn't
|
||||||
|
# register an offense in that case
|
||||||
|
node.receiver.regexp_type? || node.first_argument.regexp_type?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -99,8 +99,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def non_redundant_value_used?(receiver, node)
|
def non_redundant_value_used?(receiver, node)
|
||||||
node.value_used? &&
|
node.value_used? && !EachWithObjectInspector.new(node, receiver).value_used?
|
||||||
!EachWithObjectInspector.new(node, receiver).value_used?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def correct_multiple_elements(corrector, node, parent, new_source)
|
def correct_multiple_elements(corrector, node, parent, new_source)
|
||||||
@ -125,9 +124,7 @@ module RuboCop
|
|||||||
|
|
||||||
key = key.sym_type? && pair.colon? ? ":#{key.source}" : key.source
|
key = key.sym_type? && pair.colon? ? ":#{key.source}" : key.source
|
||||||
|
|
||||||
format(AREF_ASGN, receiver: receiver.source,
|
format(AREF_ASGN, receiver: receiver.source, key: key, value: value.source)
|
||||||
key: key,
|
|
||||||
value: value.source)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -16,25 +16,33 @@ module RuboCop
|
|||||||
include SortBlock
|
include SortBlock
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `sort` instead of `%<bad_method>s`.'
|
MSG = 'Use `sort` without block.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless (send, var_a, var_b, body = sort_with_block?(node))
|
return unless (send, var_a, var_b, body = sort_with_block?(node))
|
||||||
|
|
||||||
replaceable_body?(body, var_a, var_b) do
|
replaceable_body?(body, var_a, var_b) do
|
||||||
range = sort_range(send, node)
|
register_offense(send, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
add_offense(range, message: message(var_a, var_b)) do |corrector|
|
def on_numblock(node)
|
||||||
corrector.replace(range, 'sort')
|
return unless (send, arg_count, body = sort_with_numblock?(node))
|
||||||
end
|
return unless arg_count == 2
|
||||||
|
|
||||||
|
replaceable_body?(body, :_1, :_2) do
|
||||||
|
register_offense(send, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def message(var_a, var_b)
|
def register_offense(send, node)
|
||||||
bad_method = "sort { |#{var_a}, #{var_b}| #{var_a} <=> #{var_b} }"
|
range = sort_range(send, node)
|
||||||
format(MSG, bad_method: bad_method)
|
|
||||||
|
add_offense(range) do |corrector|
|
||||||
|
corrector.replace(range, 'sort')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -217,8 +217,7 @@ module RuboCop
|
|||||||
def find_last_match(body, range, scope_root)
|
def find_last_match(body, range, scope_root)
|
||||||
last_matches(body).find do |ref|
|
last_matches(body).find do |ref|
|
||||||
ref_pos = ref.loc.expression.begin_pos
|
ref_pos = ref.loc.expression.begin_pos
|
||||||
range.cover?(ref_pos) &&
|
range.cover?(ref_pos) && scope_root(ref) == scope_root
|
||||||
scope_root(ref) == scope_root
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -241,14 +240,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def match_gvar?(sym)
|
def match_gvar?(sym)
|
||||||
%i[
|
%i[$~ $MATCH $PREMATCH $POSTMATCH $LAST_PAREN_MATCH $LAST_MATCH_INFO].include?(sym)
|
||||||
$~
|
|
||||||
$MATCH
|
|
||||||
$PREMATCH
|
|
||||||
$POSTMATCH
|
|
||||||
$LAST_PAREN_MATCH
|
|
||||||
$LAST_MATCH_INFO
|
|
||||||
].include?(sym)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def correct_operator(corrector, recv, arg, oper = nil)
|
def correct_operator(corrector, recv, arg, oper = nil)
|
||||||
@ -17,27 +17,36 @@ module RuboCop
|
|||||||
include SortBlock
|
include SortBlock
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `sort.reverse` instead of `%<bad_method>s`.'
|
MSG = 'Use `sort.reverse` instead.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
sort_with_block?(node) do |send, var_a, var_b, body|
|
sort_with_block?(node) do |send, var_a, var_b, body|
|
||||||
replaceable_body?(body, var_b, var_a) do
|
replaceable_body?(body, var_b, var_a) do
|
||||||
range = sort_range(send, node)
|
register_offense(send, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
add_offense(range, message: message(var_a, var_b)) do |corrector|
|
def on_numblock(node)
|
||||||
replacement = 'sort.reverse'
|
sort_with_numblock?(node) do |send, arg_count, body|
|
||||||
|
next unless arg_count == 2
|
||||||
|
|
||||||
corrector.replace(range, replacement)
|
replaceable_body?(body, :_2, :_1) do
|
||||||
end
|
register_offense(send, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def message(var_a, var_b)
|
def register_offense(send, node)
|
||||||
bad_method = "sort { |#{var_a}, #{var_b}| #{var_b} <=> #{var_a} }"
|
range = sort_range(send, node)
|
||||||
format(MSG, bad_method: bad_method)
|
|
||||||
|
add_offense(range) do |corrector|
|
||||||
|
replacement = 'sort.reverse'
|
||||||
|
|
||||||
|
corrector.replace(range, replacement)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -24,10 +24,7 @@ module RuboCop
|
|||||||
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
||||||
RESTRICT_ON_SEND = %i[gsub gsub!].freeze
|
RESTRICT_ON_SEND = %i[gsub gsub!].freeze
|
||||||
|
|
||||||
PREFERRED_METHODS = {
|
PREFERRED_METHODS = { gsub: :squeeze, gsub!: :squeeze! }.freeze
|
||||||
gsub: :squeeze,
|
|
||||||
gsub!: :squeeze!
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
def_node_matcher :squeeze_candidate?, <<~PATTERN
|
def_node_matcher :squeeze_candidate?, <<~PATTERN
|
||||||
(send
|
(send
|
||||||
@ -50,8 +50,7 @@ module RuboCop
|
|||||||
include RegexpMetacharacter
|
include RegexpMetacharacter
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `String#start_with?` instead of a regex match anchored to ' \
|
MSG = 'Use `String#start_with?` instead of a regex match anchored to the beginning of the string.'
|
||||||
'the beginning of the string.'
|
|
||||||
RESTRICT_ON_SEND = %i[match =~ match?].freeze
|
RESTRICT_ON_SEND = %i[match =~ match?].freeze
|
||||||
|
|
||||||
def_node_matcher :redundant_regex?, <<~PATTERN
|
def_node_matcher :redundant_regex?, <<~PATTERN
|
||||||
@ -86,8 +86,7 @@ module RuboCop
|
|||||||
|
|
||||||
unless first_param.str_type?
|
unless first_param.str_type?
|
||||||
return true if options
|
return true if options
|
||||||
return true unless first_source.is_a?(String) &&
|
return true unless first_source.is_a?(String) && first_source =~ DETERMINISTIC_REGEX
|
||||||
first_source =~ DETERMINISTIC_REGEX
|
|
||||||
|
|
||||||
# This must be done after checking DETERMINISTIC_REGEX
|
# This must be done after checking DETERMINISTIC_REGEX
|
||||||
# Otherwise things like \s will trip us up
|
# Otherwise things like \s will trip us up
|
||||||
@ -141,8 +140,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def message(node, first_source, second_source)
|
def message(node, first_source, second_source)
|
||||||
replacement_method =
|
replacement_method = replacement_method(node, first_source, second_source)
|
||||||
replacement_method(node, first_source, second_source)
|
|
||||||
|
|
||||||
format(MSG, prefer: replacement_method, current: node.method_name)
|
format(MSG, prefer: replacement_method, current: node.method_name)
|
||||||
end
|
end
|
||||||
@ -152,8 +150,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_second_param(corrector, node, first_param)
|
def remove_second_param(corrector, node, first_param)
|
||||||
end_range = range_between(first_param.source_range.end_pos,
|
end_range = range_between(first_param.source_range.end_pos, node.source_range.end_pos)
|
||||||
node.source_range.end_pos)
|
|
||||||
|
|
||||||
corrector.replace(end_range, method_suffix(node))
|
corrector.replace(end_range, method_suffix(node))
|
||||||
end
|
end
|
||||||
@ -32,8 +32,7 @@ module RuboCop
|
|||||||
class TimesMap < Base
|
class TimesMap < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MESSAGE = 'Use `Array.new(%<count>s)` with a block ' \
|
MESSAGE = 'Use `Array.new(%<count>s)` with a block instead of `.times.%<map_or_collect>s`'
|
||||||
'instead of `.times.%<map_or_collect>s`'
|
|
||||||
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'
|
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'
|
||||||
RESTRICT_ON_SEND = %i[map collect].freeze
|
RESTRICT_ON_SEND = %i[map collect].freeze
|
||||||
|
|
||||||
@ -44,14 +43,14 @@ module RuboCop
|
|||||||
def on_block(node)
|
def on_block(node)
|
||||||
check(node)
|
check(node)
|
||||||
end
|
end
|
||||||
|
alias on_numblock on_block
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check(node)
|
def check(node)
|
||||||
times_map_call(node) do |map_or_collect, count|
|
times_map_call(node) do |map_or_collect, count|
|
||||||
add_offense(node, message: message(map_or_collect, count)) do |corrector|
|
add_offense(node, message: message(map_or_collect, count)) do |corrector|
|
||||||
replacement = "Array.new(#{count.source}" \
|
replacement = "Array.new(#{count.source}#{map_or_collect.arguments.map { |arg| ", #{arg.source}" }.join})"
|
||||||
"#{map_or_collect.arguments.map { |arg| ", #{arg.source}" }.join})"
|
|
||||||
|
|
||||||
corrector.replace(map_or_collect.loc.expression, replacement)
|
corrector.replace(map_or_collect.loc.expression, replacement)
|
||||||
end
|
end
|
||||||
@ -68,7 +67,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def_node_matcher :times_map_call, <<~PATTERN
|
def_node_matcher :times_map_call, <<~PATTERN
|
||||||
{(block $(send (send $!nil? :times) {:map :collect}) ...)
|
{({block numblock} $(send (send $!nil? :times) {:map :collect}) ...)
|
||||||
$(send (send $!nil? :times) {:map :collect} (block_pass ...))}
|
$(send (send $!nil? :times) {:map :collect} (block_pass ...))}
|
||||||
PATTERN
|
PATTERN
|
||||||
end
|
end
|
||||||
@ -15,8 +15,7 @@ module RuboCop
|
|||||||
class UriDefaultParser < Base
|
class UriDefaultParser < Base
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
|
MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of `%<double_colon>sURI::Parser.new`.'
|
||||||
'`%<double_colon>sURI::Parser.new`.'
|
|
||||||
RESTRICT_ON_SEND = %i[new].freeze
|
RESTRICT_ON_SEND = %i[new].freeze
|
||||||
|
|
||||||
def_node_matcher :uri_parser_new?, <<~PATTERN
|
def_node_matcher :uri_parser_new?, <<~PATTERN
|
||||||
@ -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.14.3'
|
STRING = '1.15.0'
|
||||||
|
|
||||||
def self.document_version
|
def self.document_version
|
||||||
STRING.match('\d+\.\d+').to_s
|
STRING.match('\d+\.\d+').to_s
|
||||||
Loading…
x
Reference in New Issue
Block a user