Sha256: 19b41be32ffccbd0109b8701c41f48ae0df65ca6aa4254575bde6396ac919f82

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

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.'.freeze

        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

15 entries across 15 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.48.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.48.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.47.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.47.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.46.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.45.0 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.44.1 lib/rubocop/cop/style/indentation_consistency.rb
rubocop-0.44.0 lib/rubocop/cop/style/indentation_consistency.rb