class RuboCop::Cop::Metrics::ClassLength


end # 4 points
)
2
1,
foo( # +1
HEREDOC
content.
Heredoc
MSG = <<~HEREDOC # +1
}
key: ‘value’
HASH = { # +1
]
2
1,
ARRAY = [ # +1
class Foo
@example CountAsOne: [‘array’, ‘hash’, ‘heredoc’, ‘method_call’]
NOTE: This cop also applies for ‘Struct` definitions.
Each construct will be counted as one line regardless of its actual size.
Available are: ’array’, ‘hash’, ‘heredoc’, and ‘method_call’.
You can set constructs you want to fold with ‘CountAsOne`.
The maximum allowed length is configurable.
Comment lines can optionally be ignored.
Checks if the length of a class exceeds some maximum value.

def find_expression_within_parent(parent)

def find_expression_within_parent(parent)
  if parent&.assignment?
    parent.expression
  elsif parent&.parent&.masgn_type?
    parent.parent.expression
  end
end

def message(length, max_length)

def message(length, max_length)
  format('Class has too many lines. [%<length>d/%<max>d]', length: length, max: max_length)
end

def on_casgn(node)

def on_casgn(node)
  block_node = node.expression || find_expression_within_parent(node.parent)
  return unless block_node.respond_to?(:class_definition?) && block_node.class_definition?
  check_code_length(block_node)
end

def on_class(node)

def on_class(node)
  check_code_length(node)
end

def on_sclass(node)

def on_sclass(node)
  return if node.each_ancestor(:class).any?
  on_class(node)
end