Sha256: a0f87d1d26264fb046071268fea2af33eadbda81888231d0d42db5cbdc85fb23

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks if there is an empty line after subject block.
      #
      # @example
      #   # bad
      #   subject(:obj) { described_class }
      #   let(:foo) { bar }
      #
      #   # good
      #   subject(:obj) { described_class }
      #
      #   let(:foo) { bar }
      class EmptyLineAfterSubject < Cop
        include RuboCop::RSpec::BlankLineSeparation

        MSG = 'Add empty line after `subject`.'

        def on_block(node)
          return unless subject?(node) && !in_spec_block?(node)
          return if last_child?(node)

          missing_separating_line(node) do |location|
            add_offense(node, location: location, message: MSG)
          end
        end

        private

        def in_spec_block?(node)
          node.each_ancestor(:block).any? do |ancestor|
            Examples::ALL.include?(ancestor.method_name)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-rspec-1.33.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb