class RuboCop::Cop::Metrics::BlockLength
NOTE: This cop does not apply for ‘Struct` definitions.
end # 5 points
HEREDOC
content.
Heredoc
msg = <<~HEREDOC # +1
}
key: ’value’
hash = { # +3
]
2
1,
array = [ # +1
something do
@example CountAsOne: [‘array’, ‘heredoc’]
for backwards compatibility. Please use ‘IgnoredMethods` instead.
NOTE: The `ExcludedMethods` configuration is deprecated and only kept
will be counted as one line regardless of its actual size.
Available are: ’array’, ‘hash’, and ‘heredoc’. Each literal
You can set literals you want to fold with ‘CountAsOne`.
The cop can be configured to ignore blocks passed to certain methods.
The maximum allowed length is configurable.
Comment lines can optionally be ignored.
This cop checks if the length of a block exceeds some maximum value.
def cop_label
def cop_label LABEL end
def method_receiver_excluded?(node)
def method_receiver_excluded?(node) node_receiver = node.receiver&.source&.gsub(/\s+/, '') node_method = String(node.method_name) ignored_methods.any? do |config| next unless config.is_a?(String) receiver, method = config.split('.') unless method method = receiver receiver = node_receiver end method == node_method && receiver == node_receiver end end
def on_block(node)
def on_block(node) return if ignored_method?(node.method_name) return if method_receiver_excluded?(node) return if node.class_constructor? || node.struct_constructor? check_code_length(node) end