Sha256: 08f05cb0889a00208699c6740c3ee07b826d21135a0b6e87d8476983ec3c0afd

Contents?: true

Size: 850 Bytes

Versions: 4

Compression:

Stored size: 850 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class EmptyLines < Cop
      MSG = 'Extra blank line detected.'
      LINE_OFFSET = 2

      def inspect(source, tokens, ast, comments)
        return if tokens.empty?

        prev_line = 1

        tokens.each do |token|
          cur_line = token.pos.line
          line_diff = cur_line - prev_line

          if line_diff > LINE_OFFSET
            # we need to be wary of comments since they
            # don't show up in the tokens
            ((prev_line + 1)...cur_line).each do |line|
              # we check if the prev and current lines are empty
              if source[line - 2].empty? && source[line - 1].empty?
                add_offence(:convention, line, MSG)
              end
            end
          end

          prev_line = cur_line
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/empty_lines.rb
rubocop-0.8.2 lib/rubocop/cop/empty_lines.rb
rubocop-0.8.1 lib/rubocop/cop/empty_lines.rb
rubocop-0.8.0 lib/rubocop/cop/empty_lines.rb