Class: RuboCop::Cop::Rouge::NoHugeCollections

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rouge/no_huge_collections.rb

Constant Summary collapse

MSG =
'Avoid collections of over 300 elements. ' \
'Place those in a lazy-loaded file, ideally ' \
'generated by a Rake task from the relevant documentation.'
RESTRICT_ON_SEND =
[:[]]
MAX_SIZE =
300

Instance Method Summary collapse

Instance Method Details

#on_array(node) ⇒ Object



29
30
31
32
33
# File 'lib/rubocop/cop/rouge/no_huge_collections.rb', line 29

def on_array(node)
  if node.children.size >= MAX_SIZE
    add_offense(node)
  end
end

#on_send(node) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/rubocop/cop/rouge/no_huge_collections.rb', line 20

def on_send(node)
  return unless set_literal?(node)

  # adjust by 2 for the target and method name
  if node.children.size - 2 > MAX_SIZE
    add_offense(node)
  end
end