Sha256: 867fde5aa7fc049e2062d657b92d87dda27e16c9e492a427fcb162d8c27a4a55

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'rubocop-rspec'
require_relative 'base'

module Gitlab
  module Styles
    module Rubocop
      module Cop
        module RSpec
          # Checks if there is an empty line after shared example blocks.
          #
          # @example
          #   # bad
          #   RSpec.describe Foo do
          #     it_behaves_like 'do this first'
          #     it_behaves_like 'does this' do
          #     end
          #     it_behaves_like 'does that' do
          #     end
          #     it_behaves_like 'do some more'
          #   end
          #
          #   # good
          #   RSpec.describe Foo do
          #     it_behaves_like 'do this first'
          #     it_behaves_like 'does this' do
          #     end
          #
          #     it_behaves_like 'does that' do
          #     end
          #
          #     it_behaves_like 'do some more'
          #   end
          #
          #   # fair - it's ok to have non-separated without blocks
          #   RSpec.describe Foo do
          #     it_behaves_like 'do this first'
          #     it_behaves_like 'does this'
          #   end
          #
          class EmptyLineAfterSharedExample < Base
            extend RuboCop::Cop::AutoCorrector
            include RuboCop::RSpec::EmptyLineSeparation

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

            def_node_matcher :shared_examples,
                             (SharedGroups::ALL + Includes::ALL).block_pattern

            def on_block(node)
              shared_examples(node) do
                break if last_child?(node)

                missing_separating_line_offense(node) do |method|
                  format(MSG, example: method)
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gitlab-styles-7.1.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-7.0.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.6.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.5.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.4.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.3.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.2.1 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.2.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.1.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-6.0.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-5.4.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-5.3.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-5.2.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-5.1.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-5.0.0 lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb