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

#offences

Instance Method Summary collapse

Methods inherited from Cop

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

Constructor Details

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

Instance Method Details

#inspect(file, source) ⇒ Object



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

def inspect(file, source)
  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, line, message)
    end
  end
end