Sha256: c474ff1ab18ba652d01dd4aa68b36929bcf34b67d366971ec81f5f2fcc649477

Contents?: true

Size: 946 Bytes

Versions: 9

Compression:

Stored size: 946 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 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(ancestor.method_name)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.3.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.2.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/empty_line_after_subject.rb
rubocop-rspec-2.0.0 lib/rubocop/cop/rspec/empty_line_after_subject.rb