Class: Tailor::Rulers::AllowTrailingLineSpacesRuler

Inherits:
Tailor::Ruler
  • Object
show all
Defined in:
lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(config, options) ⇒ AllowTrailingLineSpacesRuler

Returns a new instance of AllowTrailingLineSpacesRuler.



6
7
8
9
# File 'lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb', line 6

def initialize(config, options)
  super(config, options)
  add_lexer_observers :ignored_nl, :nl
end

Instance Method Details

#ignored_nl_update(lexed_line, lineno, column) ⇒ Object



11
12
13
14
15
16
# File 'lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb', line 11

def ignored_nl_update(lexed_line, lineno, column)
  log "Last event: #{lexed_line.last_non_line_feed_event}"
  log "Line ends with space: #{lexed_line.ends_with_sp?}"

  measure(lexed_line, lineno, column)
end

#measure(lexed_line, lineno, column) ⇒ Object

Checks to see if the line contains trailing spaces.

Parameters:

  • lexed_line (LexedLine)

    The line to check for trailing spaces.

  • lineno (Fixnum)

    Line the potential problem is on.

  • column (Fixnum)

    Column the potential problem is on.



27
28
29
30
31
32
33
34
35
# File 'lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb', line 27

def measure(lexed_line, lineno, column)
  if lexed_line.ends_with_sp?
    actual = lexed_line.last_non_line_feed_event.last.size
    problem_message = "Line has #{actual} trailing spaces."

    @problems << Problem.new(problem_type, lineno, column,
      problem_message, @options[:level])
  end
end

#nl_update(lexed_line, lineno, column) ⇒ Object



18
19
20
# File 'lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb', line 18

def nl_update(lexed_line, lineno, column)
  ignored_nl_update(lexed_line, lineno, column)
end