Class: Rubocop::Cop::MethodLength

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/method_length.rb

Constant Summary collapse

ERROR_MESSAGE =
'Method has too many lines. [%d/%d]'

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #name

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#inspect(file, source, tokens, sexp) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/method_length.rb', line 8

def inspect(file, source, tokens, sexp)
  def_token_indices(tokens, source).each do |t_ix|
    def_lineno, end_lineno = def_and_end_lines(tokens, t_ix)
    length = calculate_length(def_lineno, end_lineno, source)

    max = MethodLength.config['Max']
    if length > max
      message = sprintf(ERROR_MESSAGE, length, max)
      add_offence(:convention, def_lineno, message)
    end
  end
end