Class: Rubocop::Cop::LineLength

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

Constant Summary collapse

MSG =
'Line is too long. [%d/%d]'

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cop

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

Constructor Details

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

Class Method Details

.maxObject



18
19
20
# File 'lib/rubocop/cop/line_length.rb', line 18

def self.max
  LineLength.config['Max']
end

Instance Method Details

#inspect(source, tokens, ast, comments) ⇒ Object



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

def inspect(source, tokens, ast, comments)
  source.each_with_index do |line, index|
    max = LineLength.max
    if line.length > max
      message = sprintf(MSG, line.length, max)
      add_offence(:convention, index + 1, message)
    end
  end
end