class RuboCop::Cop::Metrics::MethodLength

Checks if the length of a method exceeds some maximum value. Comment lines can optionally be allowed. The maximum allowed length is configurable.

You can set literals you want to fold with `CountAsOne`. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

NOTE: The `ExcludedMethods` and `IgnoredMethods` configuration is deprecated and only kept for backwards compatibility. Please use `AllowedMethods` and `AllowedPatterns` instead. By default, there are no methods to allowed.

@example CountAsOne: ['array', 'heredoc']

def m
  array = [       # +1
    1,
    2
  ]

  hash = {        # +3
    key: 'value'
  }

  <<~HEREDOC      # +1
    Heredoc
    content.
  HEREDOC
end               # 5 points

Constants

LABEL

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/metrics/method_length.rb, line 51
def on_block(node)
  return unless node.send_node.method?(:define_method)

  check_code_length(node)
end
Also aliased as: on_numblock
on_def(node) click to toggle source
# File lib/rubocop/cop/metrics/method_length.rb, line 44
def on_def(node)
  return if allowed_method?(node.method_name) || matches_allowed_pattern?(node.method_name)

  check_code_length(node)
end
Also aliased as: on_defs
on_defs(node)
Alias for: on_def
on_numblock(node)
Alias for: on_block

Private Instance Methods

cop_label() click to toggle source
# File lib/rubocop/cop/metrics/method_length.rb, line 60
def cop_label
  LABEL
end