Sha256: 54a3ee98e8b63c8f3b7566023db50265e2bbf04e1c32d858bc071826cc8232be

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

require_relative '../ruler'


class Tailor
  module Rulers
    class TrailingNewlinesRuler < Tailor::Ruler
      def initialize(config, options)
        super(config, options)
        add_lexer_observers :file_end
      end

      # Checks to see if the number of newlines at the end of the file is not
      # equal to the value at +@config+.
      #
      # @param [Fixnum] trailing_newline_count The number of newlines at the end
      #   of the file.
      def measure(trailing_newline_count)
        if trailing_newline_count != @config
          lineno = "<EOF>"
          column = "<EOF>"
          msg = "File has #{trailing_newline_count} trailing "
          msg << "newlines, but should have #{@config}."

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

      # Checks to see if the file's final character is a \n.  If it is, it just
      # returns the text that was passed in.  If it's not, it adds a \n, since
      # the current indentation-checking algorithm only checks indent levels when
      # it parses a newline character (without this, indentation problems on the
      # final line won't ever get caught).
      #
      # @param [Fixnum] trailing_newline_count
      def file_end_update(trailing_newline_count)
        measure(trailing_newline_count)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tailor-1.2.1 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.2.0 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.5 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.4 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.3 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.2 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.1 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.1.0 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.0.1 lib/tailor/rulers/trailing_newlines_ruler.rb
tailor-1.0.0 lib/tailor/rulers/trailing_newlines_ruler.rb