Skip to content
Snippets Groups Projects
Unverified Commit d5aa9f8c authored by Nanda H Krishna's avatar Nanda H Krishna Committed by GitHub
Browse files

Merge pull request #11669 from...

Merge pull request #11669 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-performance-1.11.4

build(deps): bump rubocop-performance from 1.11.3 to 1.11.4 in /Library/Homebrew
parents 7c2a8f64 a7da26a2
No related branches found
No related tags found
No related merge requests found
Showing
with 14 additions and 15 deletions
......@@ -7,6 +7,7 @@ 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`
......@@ -66,7 +67,7 @@ module RuboCop
def on_send(node)
return unless (receiver, bad_method, regexp_str, replace_string = delete_prefix_candidate?(node))
return unless replace_string.blank?
return unless replace_string.empty?
good_method = PREFERRED_METHODS[bad_method]
......
......@@ -7,6 +7,7 @@ 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?`
......@@ -66,7 +67,7 @@ module RuboCop
def on_send(node)
return unless (receiver, bad_method, regexp_str, replace_string = delete_suffix_candidate?(node))
return unless replace_string.blank?
return unless replace_string.empty?
good_method = PREFERRED_METHODS[bad_method]
......
......@@ -31,14 +31,10 @@ module RuboCop
CANDIDATE_METHODS = Set[:select, :find_all, :filter].freeze
MSG = 'Use `%<prefer>s` instead of ' \
'`%<first_method>s.%<second_method>s`.'
REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of ' \
'`%<first_method>s.%<second_method>s`.'
INDEX_MSG = 'Use `%<prefer>s` instead of ' \
'`%<first_method>s[%<index>i]`.'
INDEX_REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of ' \
'`%<first_method>s[%<index>i]`.'
MSG = 'Use `%<prefer>s` instead of `%<first_method>s.%<second_method>s`.'
REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of `%<first_method>s.%<second_method>s`.'
INDEX_MSG = 'Use `%<prefer>s` instead of `%<first_method>s[%<index>i]`.'
INDEX_REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of `%<first_method>s[%<index>i]`.'
RESTRICT_ON_SEND = %i[first last []].freeze
def_node_matcher :detect_candidate?, <<~PATTERN
......
......@@ -56,23 +56,24 @@ module RuboCop
add_offense(range) do |corrector|
corrector.replace(map_node.loc.selector, 'filter_map')
corrector.remove(compact_loc.dot)
corrector.remove(compact_method_range(node))
remove_compact_method(corrector, node)
end
end
private
def compact_method_range(compact_node)
def remove_compact_method(corrector, compact_node)
chained_method = compact_node.parent
compact_method_range = compact_node.loc.selector
if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) &&
!invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
range_by_whole_lines(compact_method_range, include_final_newline: true)
compact_method_range = range_by_whole_lines(compact_method_range, include_final_newline: true)
else
compact_method_range
corrector.remove(compact_node.loc.dot)
end
corrector.remove(compact_method_range)
end
def invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment