Sha256: 8ac09db03027417a53f3c4f1ee150d93e859269cfba16227d84eacf67f1a52ee

Contents?: true

Size: 1.99 KB

Versions: 147

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # Ensures that each argument in a multi-line method call
      # starts on a separate line.
      #
      # NOTE: This cop does not move the first argument, if you want that to
      # be on a separate line, see `Layout/FirstMethodArgumentLineBreak`.
      #
      # @example
      #
      #   # bad
      #   foo(a, b,
      #     c
      #   )
      #
      #   # bad
      #   foo(a, b, {
      #     foo: "bar",
      #   })
      #
      #   # good
      #   foo(
      #     a,
      #     b,
      #     c
      #   )
      #
      #   # good
      #   foo(a, b, c)
      #
      # @example AllowMultilineFinalElement: false (default)
      #
      #   # good
      #   foo(
      #     a,
      #     b,
      #     {
      #       foo: "bar",
      #     }
      #   )
      #
      # @example AllowMultilineFinalElement: true
      #
      #   # good
      #   foo(
      #     a,
      #     b,
      #     {
      #       foo: "bar",
      #     }
      #   )
      #
      class MultilineMethodArgumentLineBreaks < Base
        include MultilineElementLineBreaks
        extend AutoCorrector

        MSG = 'Each argument in a multi-line method call must start on a separate line.'

        def on_send(node)
          return if node.method?(:[]=)

          args = node.arguments

          # If there is a trailing hash arg without explicit braces, like this:
          #
          #    method(1, 'key1' => value1, 'key2' => value2)
          #
          # ...then each key/value pair is treated as a method 'argument'
          # when determining where line breaks should appear.
          last_arg = args.last
          args = args[0...-1] + last_arg.children if last_arg&.hash_type? && !last_arg&.braces?

          check_line_breaks(node, args, ignore_last: ignore_last_element?)
        end

        private

        def ignore_last_element?
          !!cop_config['AllowMultilineFinalElement']
        end
      end
    end
  end
end

Version data entries

147 entries across 146 versions & 15 rubygems

Version Path
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb