Class: RuboCop::Cop::RSpec::EmptyLineAfterExample
- Inherits:
-
Base
- Object
- Base
- Base
- RuboCop::Cop::RSpec::EmptyLineAfterExample
show all
- Extended by:
- AutoCorrector
- Includes:
- EmptyLineSeparation
- Defined in:
- lib/rubocop/cop/rspec/empty_line_after_example.rb
Overview
Checks if there is an empty line after example blocks.
Constant Summary
collapse
- MSG =
'Add an empty line after `%<example>s`.'
Instance Method Summary
collapse
#last_child?, #missing_separating_line, #missing_separating_line_offense, #offending_loc
#final_end_location
Methods inherited from Base
inherited, #on_new_investigation
#block_pattern, #send_pattern
Instance Method Details
#allow_consecutive_one_liners? ⇒ Boolean
63
64
65
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 63
def allow_consecutive_one_liners?
cop_config['AllowConsecutiveOneLiners']
end
|
#allowed_one_liner?(node) ⇒ Boolean
59
60
61
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 59
def allowed_one_liner?(node)
consecutive_one_liner?(node) && allow_consecutive_one_liners?
end
|
#consecutive_one_liner?(node) ⇒ Boolean
67
68
69
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 67
def consecutive_one_liner?(node)
node.line_count == 1 && next_one_line_example?(node)
end
|
#next_one_line_example?(node) ⇒ Boolean
71
72
73
74
75
76
77
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 71
def next_one_line_example?(node)
next_sibling = next_sibling(node)
return unless next_sibling
return unless example?(next_sibling)
next_sibling.line_count == 1
end
|
#next_sibling(node) ⇒ Object
79
80
81
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 79
def next_sibling(node)
node.parent.children[node.sibling_index + 1]
end
|
#on_block(node) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 50
def on_block(node)
return unless example?(node)
return if allowed_one_liner?(node)
missing_separating_line_offense(node) do |method|
format(MSG, example: method)
end
end
|