class RuboCop::Cop::Layout::AlignArguments
Here we check if the arguments on a multi-line method definition are aligned.
@example EnforcedStyle: with_first_argument (default)
# good foo :bar, :baz foo( :bar, :baz ) # bad foo :bar, :baz foo( :bar, :baz )
@example EnforcedStyle: with_fixed_indentation
# good foo :bar, :baz # bad foo :bar, :baz
Constants
- ALIGN_PARAMS_MSG
- FIXED_INDENT_MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 57 def autocorrect(node) AlignmentCorrector.correct(processed_source, node, column_delta) end
on_send(node)
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 49 def on_send(node) return if node.arguments.size < 2 || node.send_type? && node.method?(:[]=) check_alignment(node.arguments, base_column(node, node.arguments)) end
Also aliased as: on_csend
Private Instance Methods
base_column(node, args)
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 71 def base_column(node, args) if fixed_indentation? lineno = target_method_lineno(node) line = node.source_range.source_buffer.source_line(lineno) indentation_of_line = /\S.*/.match(line).begin(0) indentation_of_line + configured_indentation_width else display_column(args.first.source_range) end end
fixed_indentation?()
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 67 def fixed_indentation? cop_config['EnforcedStyle'] == 'with_fixed_indentation' end
message(_node)
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 63 def message(_node) fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG end
target_method_lineno(node)
click to toggle source
# File lib/rubocop/cop/layout/align_arguments.rb, line 82 def target_method_lineno(node) if node.loc.selector node.loc.selector.line else # l.(1) has no selector, so we use the opening parenthesis instead node.loc.begin.line end end