class RuboCop::Cop::RSpec::EmptyLineAfterFinalLet
Checks if there is an empty line after the last let block.
@example
# bad let(:foo) { bar } let(:something) { other } it do ... end # good let(:foo) { bar } let(:something) { other } it do ... end
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_final_let.rb, line 40 def autocorrect(node) loc = last_node_loc(node) ->(corrector) { corrector.insert_after(loc.end, "\n") } end
on_block(node)
click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_final_let.rb, line 27 def on_block(node) return unless example_group_with_body?(node) latest_let = node.body.child_nodes.select { |child| let?(child) }.last return if latest_let.nil? return if latest_let.equal?(node.body.children.last) no_new_line_after(latest_let) do add_offense(latest_let, location: :expression) end end
Private Instance Methods
heredoc_line(node) { |loc.heredoc_end| ... }
click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_final_let.rb, line 63 def heredoc_line(node, &block) yield node.loc.heredoc_end if node.loc.respond_to?(:heredoc_end) node.each_child_node { |child| heredoc_line(child, &block) } end
last_node_loc(node)
click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_final_let.rb, line 55 def last_node_loc(node) last_line = node.loc.end.line heredoc_line(node) do |loc| return loc if loc.line > last_line end node.loc.end end
no_new_line_after(node) { || ... }
click to toggle source
# File lib/rubocop/cop/rspec/empty_line_after_final_let.rb, line 47 def no_new_line_after(node) loc = last_node_loc(node) next_line = processed_source[loc.line] yield unless next_line.blank? end