Class: Rubocop::Cop::LineLength

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

Constant Summary collapse

ERROR_MESSAGE =
'Line is too long. [%d/%d]'
MAX_LINE_LENGTH =
79

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, enabled?, #has_report?, inherited, #initialize

Constructor Details

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

Instance Method Details

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



9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/line_length.rb', line 9

def inspect(file, source, tokens, sexp)
  source.each_with_index do |line, index|
    if line.length > MAX_LINE_LENGTH
      message = sprintf(ERROR_MESSAGE, line.length, MAX_LINE_LENGTH)
      add_offence(:convention, index + 1, message)
    end
  end
end