Sha256: 27eab51d0827da7784bd5795f3499076b2bc6dfba33f06776670fb619f0bc369

Contents?: true

Size: 972 Bytes

Versions: 6

Compression:

Stored size: 972 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 < Base
        extend AutoCorrector
        include RuboCop::RSpec::EmptyLineSeparation

        MSG = 'Add an empty line after `%<subject>s`.'

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

          missing_separating_line_offense(node) do |method|
            format(MSG, subject: method)
          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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-rspec-2.0.0.pre lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb