Sha256: 9798f2304278c782bdc2edf530a1791a412f280f92a0eb9ab72e59ec1bfb0fe9

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # Here we check if the parameters on a multi-line method call are
      # aligned.
      class AlignParameters < Cop
        MSG = 'Align the parameters of a method call if they span ' +
          'more than one line.'

        def on_send(node)
          _receiver, method, *args = *node

          if method != :[]= && args.size > 1
            first_arg_col = args.first.loc.expression.column
            prev_arg_line = args.first.loc.expression.line
            prev_arg_col = first_arg_col

            args.each do |arg|
              cur_arg_line = arg.loc.expression.line
              cur_arg_col = arg.loc.expression.column

              if cur_arg_line != prev_arg_line &&
                  cur_arg_col != first_arg_col
                add_offence(:convention, arg.loc.expression, MSG)
              end

              prev_arg_col = cur_arg_col
              prev_arg_line = cur_arg_line
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.10.0 lib/rubocop/cop/style/align_parameters.rb