Class: RuboCop::Cop::RSpec::EmptyLineAfterHook

Inherits:
Cop
  • Object
show all
Includes:
RSpec::BlankLineSeparation
Defined in:
lib/rubocop/cop/rspec/empty_line_after_hook.rb

Overview

Checks if there is an empty line after hook blocks.

Examples:

# bad
before { do_something }
it { does_something }

# bad
after { do_something }
it { does_something }

# bad
around { |test| test.run }
it { does_something }

# good
before { do_something }

it { does_something }

# good
after { do_something }

it { does_something }

# good
around { |test| test.run }

it { does_something }

Constant Summary collapse

MSG =
'Add an empty line after `%<hook>s`.'

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL, RSpec::Language::RSPEC

Instance Method Summary collapse

Methods included from RSpec::BlankLineSeparation

#autocorrect, #last_child?, #missing_separating_line, #offending_loc

Methods included from RSpec::FinalEndLocation

#final_end_location

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_block(node) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubocop/cop/rspec/empty_line_after_hook.rb', line 41

def on_block(node)
  return unless hook?(node)
  return if last_child?(node)

  missing_separating_line(node) do |location|
    add_offense(
      node,
      location: location,
      message: format(MSG, hook: node.method_name)
    )
  end
end