Skip to content

Commit

Permalink
Avoid collection literals in method
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Sep 4, 2022
1 parent fdd3727 commit ca54649
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/rubocop/cop/performance/compare_with_block.rb
Expand Up @@ -3,6 +3,8 @@
module RuboCop
module Cop
module Performance
KEY_TYPES = %i[sym str int].freeze

# Identifies places where `sort { |a, b| a.foo <=> b.foo }`
# can be replaced by `sort_by(&:foo)`.
# This cop also checks `max` and `min` methods.
Expand Down Expand Up @@ -73,7 +75,7 @@ def slow_compare?(method, args_a, args_b)
return false unless args_a.size == 1

key = args_a.first
return false unless %i[sym str int].include?(key.type)
return false unless KEY_TYPES.include?(key.type)
else
return false unless args_a.empty?
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/performance/regexp_match.rb
Expand Up @@ -81,6 +81,7 @@ class RegexpMatch < Base
# Constants are included in this list because it is unlikely that
# someone will store `nil` as a constant and then use it for comparison
TYPES_IMPLEMENTING_MATCH = %i[const regexp str sym].freeze
GVAR_SYMS = %i[$~ $MATCH $PREMATCH $POSTMATCH $LAST_PAREN_MATCH $LAST_MATCH_INFO].freeze
MSG = 'Use `match?` instead of `%<current>s` when `MatchData` is not used.'

def_node_matcher :match_method?, <<~PATTERN
Expand Down Expand Up @@ -240,7 +241,7 @@ def scope_root(node)
end

def match_gvar?(sym)
%i[$~ $MATCH $PREMATCH $POSTMATCH $LAST_PAREN_MATCH $LAST_MATCH_INFO].include?(sym)
GVAR_SYMS.include?(sym)
end

def correct_operator(corrector, recv, arg, oper = nil)
Expand Down

0 comments on commit ca54649

Please sign in to comment.