Sha256: dac6c354a8c71933909159cb20ac49bddf8870ce33a19360b555bb2d19cae772

Contents?: true

Size: 706 Bytes

Versions: 3

Compression:

Stored size: 706 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks whether the *when*s of a *case* expression
      # are indented as deep as its *case* keyword.
      #
      # It will register a separate offence for each misaligned *when*.
      class CaseIndentation < Cop
        MSG = 'Indent when as deep as case.'

        def on_case(case_node)
          _condition, *whens, _else = *case_node

          case_column = case_node.location.keyword.column

          whens.each do |when_node|
            pos = when_node.loc.keyword
            add_offence(:convention, pos, MSG) if pos.column != case_column
          end

          super
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rubocop-0.9.1 lib/rubocop/cop/style/case_indentation.rb
sabat-rubocop-0.9.0 lib/rubocop/cop/style/case_indentation.rb
rubocop-0.9.0 lib/rubocop/cop/style/case_indentation.rb