Class: RuboCop::Cop::RSpec::EmptyLineAfterExample

Inherits:
Base
  • Object
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.

Examples:

# bad
RSpec.describe Foo do
  it 'does this' do
  end
  it 'does that' do
  end
end

# good
RSpec.describe Foo do
  it 'does this' do
  end

  it 'does that' do
  end
end

# fair - it's ok to have non-separated one-liners
RSpec.describe Foo do
  it { one }
  it { two }
end

with AllowConsecutiveOneLiners configuration

# rubocop.yml
# RSpec/EmptyLineAfterExample:
#   AllowConsecutiveOneLiners: false

# bad
RSpec.describe Foo do
  it { one }
  it { two }
end

Constant Summary collapse

MSG =
'Add an empty line after `%<example>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_or_numblock_pattern, #block_pattern, #numblock_pattern, #send_pattern

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/rspec/empty_line_after_example.rb', line 49

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  return unless example?(node)
  return if allowed_one_liner?(node)

  missing_separating_line_offense(node) do |method|
    format(MSG, example: method)
  end
end