Class: Gitlab::Styles::Rubocop::Cop::RSpec::EmptyLineAfterLetBlock

Inherits:
Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::RSpec::EmptyLineSeparation
Defined in:
lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb

Overview

Checks if there is an empty line after let blocks.

Examples:

# bad
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:another_thing) do
  end
  let(:something_else) do
  end
  let(:last_thing) { 'last thing' }
end

# good
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:another_thing) do
  end

  let(:something_else) do
  end

  let(:last_thing) { 'last thing' }
end

# good - it's ok to have non-separated without do/end blocks
RSpec.describe Foo do
  let(:something) { 'something' }
  let(:last_thing) { 'last thing' }
end

Constant Summary collapse

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

Constants included from Rspec::Helpers

Rspec::Helpers::LET, Rspec::Helpers::LET_IT_BE_HELPERS

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb', line 50

def on_block(node)
  lets(node) do
    break if last_child?(node)
    next if node.single_line?

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