lib/rubocop/cop/rspec/single_line_hook.rb in gitlab-styles-8.0.0 vs lib/rubocop/cop/rspec/single_line_hook.rb in gitlab-styles-9.0.0
- old
+ new
@@ -4,11 +4,11 @@
require_relative 'base'
module Rubocop
module Cop
module RSpec
- # This cop checks for single-line hook blocks
+ # Checks for single-line hook blocks
#
# @example
#
# # bad
# before { do_something }
@@ -23,19 +23,21 @@
# undo_something
# end
class SingleLineHook < Base
MESSAGE = "Don't use single-line hook blocks."
+ # @!method rspec_hook?(node)
def_node_search :rspec_hook?, <<~PATTERN
(send nil? {:after :around :before} ...)
PATTERN
def on_block(node)
return unless node.single_line?
return unless rspec_hook?(node)
add_offense(node, message: MESSAGE)
end
+ alias_method :on_numblock, :on_block
end
end
end
end