Class: RuboCop::Cop::Greenroom::ScienceBlockShape
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Greenroom::ScienceBlockShape
- Defined in:
- lib/rubocop/cop/greenroom/science_block_shape.rb
Overview
Requires a Scientist.run block to hold use, try, and compare,
once each, in that order, and to hold nothing else.
The order carries weight beyond taste. The gate that decides whether a
change may merge compares the method body before the change against the
body inside use. A fixed shape lets it find use directly, and a
free arrangement would put a search in front of that comparison. A
reader who wants to write the shape by hand also gets one form to copy
rather than several.
This cop reports what one file shows, so silence means that this cop cannot tell rather than that a change is accepted.
Constant Summary collapse
- MSG =
"A Scientist.run block must contain use, try, and compare once, in that order."
Instance Method Summary collapse
Instance Method Details
#on_block(node) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rubocop/cop/greenroom/science_block_shape.rb', line 21 def on_block(node) return unless science_block?(node) calls = body_expressions(node).map { |expression| science_call(expression, node) } add_offense(node.send_node) unless calls == %i[use try compare] end |