lib/rubocop/cop/performance/io_readlines.rb in rubocop-performance-1.8.1 vs lib/rubocop/cop/performance/io_readlines.rb in rubocop-performance-1.9.0
- old
+ new
@@ -27,18 +27,18 @@
class IoReadlines < Base
include RangeHelp
extend AutoCorrector
MSG = 'Use `%<good>s` instead of `%<bad>s`.'
- ENUMERABLE_METHODS = (Enumerable.instance_methods + [:each]).freeze
+ RESTRICT_ON_SEND = (Enumerable.instance_methods + [:each]).freeze
def_node_matcher :readlines_on_class?, <<~PATTERN
- $(send $(send (const nil? {:IO :File}) :readlines ...) #enumerable_method?)
+ $(send $(send (const nil? {:IO :File}) :readlines ...) _)
PATTERN
def_node_matcher :readlines_on_instance?, <<~PATTERN
- $(send $(send ${nil? !const_type?} :readlines ...) #enumerable_method? ...)
+ $(send $(send ${nil? !const_type?} :readlines ...) _ ...)
PATTERN
def on_send(node)
return unless (captured_values = readlines_on_class?(node) || readlines_on_instance?(node))
@@ -52,13 +52,9 @@
autocorrect(corrector, enumerable_call, readlines_call, receiver)
end
end
private
-
- def enumerable_method?(node)
- ENUMERABLE_METHODS.include?(node.to_sym)
- end
def autocorrect(corrector, enumerable_call, readlines_call, receiver)
# We cannot safely correct `.readlines` method called on IO/File classes
# due to its signature and we are not sure with implicit receiver
# if it is called in the context of some instance or mentioned class.