Sha256: 76a1861ca4711578441157878ff528327c992e87e0fb93a185062918cd884488

Contents?: true

Size: 976 Bytes

Versions: 11

Compression:

Stored size: 976 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)
          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

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-rspec-1.41.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.40.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.39.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.38.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.38.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.37.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.37.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.36.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.35.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.34.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-1.34.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb