Class: RungerStyle::MultilineMethodArgumentsLineBreaks
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- RungerStyle::MultilineMethodArgumentsLineBreaks
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp
- Defined in:
- lib/runger_style/cops/default/multiline_method_arguments_line_breaks.rb
Constant Summary collapse
- MSG =
'Each argument in a multi-line method call must start on a separate line.'
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/runger_style/cops/default/multiline_method_arguments_line_breaks.rb', line 10 def on_send(node) if node.arguments? && multiline_method_call?(node) # When a method call uses keyword arguments without braces, # the parser produces a single hash node. In that case, inspect its pairs. arguments = if node.arguments.one? && node.arguments.first.hash_type? && !node.arguments.first.braces? node.arguments.first.pairs else node.arguments end arguments.each_cons(2) do |arg1, arg2| if same_line?(arg1, arg2) separator = separator_range(arg1, arg2) add_offense(separator, message: MSG) do |corrector| base_indent = base_indentation(arg1) replacement = ",\n#{base_indent}" corrector.replace(separator, replacement) end end end end end |