Class: RuboCop::Cop::Vicenzo::Layout::MultilineMethodCallLineBreaks

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/vicenzo/layout/multiline_method_call_line_breaks.rb

Overview

Enforces that method calls in a multiline chain are each on their own line.

If a method chain spans more than one line, this cop ensures that every call in the chain is placed on a new line. It prevents "mixed" styles where some methods are on the same line as the receiver while others are broken.

Configuration

This cop allows you to customize the indentation width used during auto-correction. The default width is 2 spaces relative to the previous line.

CustomCops/MultilineMethodCallLineBreaks:
  IndentationWidth: 4 # (default is 2)

Examples:

# bad
object.method_one
  .method_two

# bad
object
  .method_one.method_two
  .method_three

# good - single line chain
object.method_one.method_two

# good - multiline chain
object
  .method_one
  .method_two

# good - arguments causing the break (if configured implicitly)
object.method_one(
  arg1,
  arg2
).method_two

Constant Summary collapse

MSG =
'Method calls in a multiline chain must each be on their own line.'
DEFAULT_INDENTATION_WIDTH =
2
LEADING_SPACES_PATTERN =
/\A */
CHAIN_START_PATTERN =
/\A\s*&?\./
OPERATOR_METHODS =
%i[[] []= + - * / % ** << >>].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



57
58
59
# File 'lib/rubocop/cop/vicenzo/layout/multiline_method_call_line_breaks.rb', line 57

def on_send(node)
  check_node(node)
end