Class: RuboCop::Cop::RSpec::EmptyLineAfterSubject

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/empty_line_after_subject.rb

Overview

Checks if there is an empty line after subject block.

Examples:

# bad
subject(:obj) { described_class }
let(:foo) { bar }

# good
subject(:obj) { described_class }

let(:foo) { bar }

Constant Summary collapse

MSG =
'Add empty line after `subject`.'.freeze

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL

Instance Method Summary collapse

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#autocorrect(node) ⇒ Object



33
34
35
# File 'lib/rubocop/cop/rspec/empty_line_after_subject.rb', line 33

def autocorrect(node)
  ->(corrector) { corrector.insert_after(node.loc.end, "\n") }
end

#on_block(node) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rubocop/cop/rspec/empty_line_after_subject.rb', line 22

def on_block(node)
  return unless subject?(node) && !in_spec_block?(node)
  return if node.equal?(node.parent.children.last)

  send_line = node.loc.end.line
  next_line = processed_source[send_line]
  return if next_line.blank?

  add_offense(node, location: :expression, message: MSG)
end