Sha256: 03ed1562f7c1a54f38569a2f3354340d18a34a785bae456e970a5e7fc28e4d04

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks whether method definitions are
      # separated by empty lines.
      class EmptyLineBetweenDefs < Cop
        MSG = 'Use empty lines between defs.'

        def on_def(node)
          if @prev_def_end && (def_start(node) - @prev_def_end) == 1
            unless @prev_was_single_line && singe_line_def?(node) &&
                cop_config['AllowAdjacentOneLineDefs']
              add_offense(node, :keyword)
            end
          end

          @prev_def_end = def_end(node)
          @prev_was_single_line = singe_line_def?(node)
        end

        private

        def singe_line_def?(node)
          def_start(node) == def_end(node)
        end

        def def_start(node)
          node.loc.keyword.line
        end

        def def_end(node)
          node.loc.end.line
        end

        def autocorrect(node)
          range = range_with_surrounding_space(node.loc.expression, :left)
          @corrections << lambda do |corrector|
            corrector.insert_before(range, "\n")
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/empty_line_between_defs.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.26.1 lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.26.0 lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.25.0 lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.24.1 lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.24.0 lib/rubocop/cop/style/empty_line_between_defs.rb
rubocop-0.23.0 lib/rubocop/cop/style/empty_line_between_defs.rb