class RuboCop::Cop::Metrics::ModuleLength

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

You can set constructs you want to fold with ‘CountAsOne`.

Available are: ‘array’, ‘hash’, ‘heredoc’, and ‘method_call’. Each construct will be counted as one line regardless of its actual size.

@example CountAsOne: [‘array’, ‘hash’, ‘heredoc’, ‘method_call’]

module M
  ARRAY = [         # +1
    1,
    2
  ]

  HASH = {          # +1
    key: 'value'
  }

  MSG = <<~HEREDOC  # +1
    Heredoc
    content.
  HEREDOC

  foo(              # +1
    1,
    2
  )
end                 # 4 points

Public Instance Methods

on_casgn(node) click to toggle source
# File lib/rubocop/cop/metrics/module_length.rb, line 45
def on_casgn(node)
  module_definition?(node) { check_code_length(node) }
end
on_module(node) click to toggle source
# File lib/rubocop/cop/metrics/module_length.rb, line 41
def on_module(node)
  check_code_length(node)
end

Private Instance Methods

message(length, max_length) click to toggle source
# File lib/rubocop/cop/metrics/module_length.rb, line 56
def message(length, max_length)
  format('Module has too many lines. [%<length>d/%<max>d]', length: length, max: max_length)
end