Sha256: 49e80e48c2df9683ce8c1866ffb902e477ce70ff4fbc218060e74e0c20515fb8

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

require_relative '../ruler'

class Tailor
  module Rulers
    class MaxLineLengthRuler < 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 "<#{self.class}> Line length: #{lexed_line.line_length}"
        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 has more characters that given at +@config+.
      #
      # @param [Fixnum] lexed_line The line to measure.
      # @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.line_length > @config
          msg = "Line is #{lexed_line.line_length} chars long, "
          msg << "but should be #{@config}."

          @problems << Problem.new(problem_type, lineno, column, msg,
            @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/max_line_length_ruler.rb
tailor-1.4.0 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.3.1 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.3.0 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.2.1 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.2.0 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.5 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.4 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.3 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.2 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.1 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.1.0 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.0.1 lib/tailor/rulers/max_line_length_ruler.rb
tailor-1.0.0 lib/tailor/rulers/max_line_length_ruler.rb