Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /rubocop/cop/rspec
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'rubocop/cop/rspec')
-rw-r--r--rubocop/cop/rspec/empty_line_after_shared_example.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/rubocop/cop/rspec/empty_line_after_shared_example.rb b/rubocop/cop/rspec/empty_line_after_shared_example.rb
new file mode 100644
index 00000000000..5d09565bd5a
--- /dev/null
+++ b/rubocop/cop/rspec/empty_line_after_shared_example.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require 'rubocop/rspec/final_end_location'
+require 'rubocop/rspec/blank_line_separation'
+require 'rubocop/rspec/language'
+
+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 < RuboCop::Cop::Cop
+ include RuboCop::RSpec::BlankLineSeparation
+ include RuboCop::RSpec::Language
+
+ 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(node) do |location|
+ add_offense(node,
+ location: location,
+ message: format(MSG, example: node.method_name))
+ end
+ end
+ end
+ end
+ end
+ end
+end