Sha256: 831a4295b128d360682feda363349764e4dea4b5532a785663b2cc75bc3794c3

Contents?: true

Size: 858 Bytes

Versions: 15

Compression:

Stored size: 858 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class EmptyLines < Cop
      ERROR_MESSAGE = 'Use empty lines between defs.'

      def inspect(file, source, tokens, sexp)
        each_parent_of(:def, sexp) do |parent|
          defs = parent.select { |child| child[0] == :def }
          identifier_of_first_def = defs[0][1]
          current_row_ix = identifier_of_first_def[-1].lineno - 1
          # The first def doesn't need to have an empty line above it,
          # so we iterate starting at index 1.
          defs[1..-1].each do |child|
            next_row_ix = child[1][-1].lineno - 1
            if source[current_row_ix..next_row_ix].grep(/^[ \t]*$/).empty?
              add_offence(:convention, next_row_ix + 1, ERROR_MESSAGE)
            end
            current_row_ix = next_row_ix
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubocop-0.6.1 lib/rubocop/cop/empty_lines.rb
rubocop-0.6.0 lib/rubocop/cop/empty_lines.rb
rubocop-0.5.0 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.6 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.5 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.4 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.3 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.2 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.1 lib/rubocop/cop/empty_lines.rb
rubocop-0.4.0 lib/rubocop/cop/empty_lines.rb
rubocop-0.3.2 lib/rubocop/cop/empty_lines.rb
rubocop-0.3.1 lib/rubocop/cop/empty_lines.rb
rubocop-0.3.0 lib/rubocop/cop/empty_lines.rb
rubocop-0.2.1 lib/rubocop/cop/empty_lines.rb
rubocop-0.2.0 lib/rubocop/cop/empty_lines.rb