Sha256: 7ed437e2523ba57c8af6e05e446342a294ed97c2e9d73f27ae8c46eb0ac17174

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

require_relative '../ruler'

class Tailor
  module Rulers
    class AllowTrailingLineSpacesRuler < Tailor::Ruler
      def initialize(config, options)
        super(config, options)
        add_lexer_observers :ignored_nl, :nl
      end

      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

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

      # Checks to see if the line contains trailing spaces.
      #
      # @param [LexedLine] lexed_line The line to check for trailing spaces.
      # @param [Fixnum] lineno Line the potential problem is on.
      # @param [Fixnum] column Column the potential problem is on.
      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tailor-1.4.1 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.4.0 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.3.1 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.3.0 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.2.1 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.2.0 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.5 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.4 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.3 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.2 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.1 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.1.0 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.0.1 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb
tailor-1.0.0 lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb