forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
empty_line_after_subject.rb
41 lines (35 loc) · 976 Bytes
/
empty_line_after_subject.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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