Sha256: bf79ee067446d7c5e188570cc05b077356f8bd6be910d00336e620abf4112d3a

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cops checks for inconsistent indentation.
      #
      # @example
      #
      #   class A
      #     def test
      #       puts 'hello'
      #        puts 'world'
      #     end
      #   end
      class IndentationConsistency < Cop
        include AutocorrectAlignment
        include AccessModifierNode
        include ConfigurableEnforcedStyle

        MSG = 'Inconsistent indentation detected.'

        def on_begin(node)
          check(node)
        end

        def on_kwbegin(node)
          check(node)
        end

        private

        def check(node)
          children_to_check = [[]]
          node.children.each do |child|
            # Modifier nodes have special indentation and will be checked by
            # the AccessModifierIndentation cop. This cop uses them as dividers
            # in rails mode. Then consistency is checked only within each
            # section delimited by a modifier node.
            if modifier_node?(child)
              children_to_check << [] if style == :rails
            else
              children_to_check.last << child
            end
          end
          children_to_check.each { |group| check_alignment(group) }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.35.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.34.2 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.34.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.34.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.33.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.32.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.32.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.31.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.30.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.30.0 lib/rubocop/cop/style/indentation_consistency.rb