Sha256: dbb8b21c1e6b591f1ad66695744f0ad03e3fbe52068f1151c3555630d68ba37b

Contents?: true

Size: 689 Bytes

Versions: 4

Compression:

Stored size: 689 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
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.12.0 lib/rubocop/cop/style/case_indentation.rb
rubocop-0.11.1 lib/rubocop/cop/style/case_indentation.rb
rubocop-0.11.0 lib/rubocop/cop/style/case_indentation.rb
rubocop-0.10.0 lib/rubocop/cop/style/case_indentation.rb