Class: RuboCop::Cop::RSpec::EmptyLineAfterFinalLet

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
EmptyLineSeparation
Defined in:
lib/rubocop/cop/rspec/empty_line_after_final_let.rb

Overview

Checks if there is an empty line after the last let block.

Examples:

# bad
let(:foo) { bar }
let(:something) { other }
it { does_something }

# good
let(:foo) { bar }
let(:something) { other }

it { does_something }

Constant Summary collapse

MSG =
'Add an empty line after the last `%<let>s`.'

Instance Method Summary collapse

Methods included from EmptyLineSeparation

#last_child?, #missing_separating_line, #missing_separating_line_offense, #offending_loc

Methods included from FinalEndLocation

#final_end_location

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_block(node) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/rspec/empty_line_after_final_let.rb', line 25

def on_block(node)
  return unless example_group_with_body?(node)

  final_let = node.body.child_nodes.reverse.find { |child| let?(child) }

  return if final_let.nil?

  missing_separating_line_offense(final_let) do |method|
    format(MSG, let: method)
  end
end