Sha256: d1785a92ff669a8548d646e572c7ca5e808de1f39ad41ecfb16ebae31726fecd

Contents?: true

Size: 1.47 KB

Versions: 19

Compression:

Stored size: 1.47 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 AssignmentIndentation < Base
        include CheckAssignment
        include Alignment
        extend AutoCorrector

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

        private

        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(corrector, node)
          AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
        end

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

          leftmost_multiple_assignment(node.parent)

          node.parent
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
rubocop-1.22.1 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.22.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.21.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.20.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.19.1 lib/rubocop/cop/layout/assignment_indentation.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.19.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.18.4 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.18.3 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.18.2 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.18.1 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.18.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.17.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.16.1 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.16.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.15.0 lib/rubocop/cop/layout/assignment_indentation.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.14.0 lib/rubocop/cop/layout/assignment_indentation.rb
rubocop-1.13.0 lib/rubocop/cop/layout/assignment_indentation.rb