Sha256: 34e5b58015179659e097ecd5899613107ec3a945667337e31060e5cbfd0cbdd4

Contents?: true

Size: 944 Bytes

Versions: 4

Compression:

Stored size: 944 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    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(:convetion,
                          cur_arg_line,
                          MSG)
            end

            prev_arg_col = cur_arg_col
            prev_arg_line = cur_arg_line
          end
        end

        super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/align_parameters.rb
rubocop-0.8.2 lib/rubocop/cop/align_parameters.rb
rubocop-0.8.1 lib/rubocop/cop/align_parameters.rb
rubocop-0.8.0 lib/rubocop/cop/align_parameters.rb