Sha256: 11edf1eb0ec73747ffed0915942ffe253a579fd7ca6d25e1f8024427f4020d8d

Contents?: true

Size: 553 Bytes

Versions: 3

Compression:

Stored size: 553 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks for *when;* uses in *case* expressions.
      class WhenThen < Cop
        MSG = 'Never use `when x;`. Use `when x then` instead.'

        def on_when(node)
          if node.loc.begin && node.loc.begin.is?(';')
            add_offense(node, :begin)
          end
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            corrector.replace(node.loc.begin, ' then')
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.21.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.20.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.20.0 lib/rubocop/cop/style/when_then.rb