Module: Rubocop::Cop::Style::CodeLength

Includes:
ConfigurableMax
Included in:
ClassLength, MethodLength
Defined in:
lib/rubocop/cop/style/code_length.rb

Overview

Common functionality for checking length of code segments.

Instance Method Summary collapse

Methods included from ConfigurableMax

#max=

Instance Method Details

#check(node, *_) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rubocop/cop/style/code_length.rb', line 18

def check(node, *_)
  length = code_length(node)
  if length > max_length
    add_offence(node, :keyword, sprintf(message, length,
                                        max_length)) do
      self.max = length
    end
  end
end

#count_comments?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rubocop/cop/style/code_length.rb', line 14

def count_comments?
  cop_config['CountComments']
end

#irrelevant_line(source_line) ⇒ Object

Returns true for lines that shall not be included in the count.



29
30
31
# File 'lib/rubocop/cop/style/code_length.rb', line 29

def irrelevant_line(source_line)
  source_line.blank? || !count_comments? && comment_line?(source_line)
end

#max_lengthObject



10
11
12
# File 'lib/rubocop/cop/style/code_length.rb', line 10

def max_length
  cop_config['Max']
end