Sha256: 981a79b597da72f2f88ff74b38c9a30886090a3ff8ef11de0a954a5b07cf72ff

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This cop checks the indentation of the first line of the
      # right-hand-side of a multi-line assignment.
      #
      # @example
      #   # bad
      #   value =
      #   if foo
      #     'bar'
      #   end
      #
      #   # good
      #   value =
      #     if foo
      #       'bar'
      #     end
      #
      # The indentation of the remaining lines can be corrected with
      # other cops such as `IndentationConsistency` and `EndAlignment`.
      class IndentAssignment < Cop
        include CheckAssignment
        include Alignment

        MSG = 'Indent the first line of the right-hand-side of a ' \
              'multi-line assignment.'

        def check_assignment(node, rhs)
          return unless rhs
          return unless node.loc.operator
          return if node.loc.operator.line == rhs.first_line

          base = display_column(leftmost_multiple_assignment(node).source_range)
          check_alignment([rhs], base + configured_indentation_width)
        end

        def autocorrect(node)
          AlignmentCorrector.correct(processed_source, node, column_delta)
        end

        def leftmost_multiple_assignment(node)
          return node unless node.parent&.assignment?

          leftmost_multiple_assignment(node.parent)

          node.parent
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/indent_assignment.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/indent_assignment.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/indent_assignment.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/indent_assignment.rb
rubocop-0.75.0 lib/rubocop/cop/layout/indent_assignment.rb