Sha256: 470c7c3708be4ab0724ecf3a64c9e706ee470077fd6c3ab1d22a0a6c77fe635c

Contents?: true

Size: 550 Bytes

Versions: 6

Compression:

Stored size: 550 Bytes

Contents

# encoding: utf-8

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

        def on_when(node)
          return unless node.loc.begin && node.loc.begin.is?(';')

          add_offense(node, :begin)
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.30.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.30.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.29.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.29.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.28.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.27.1 lib/rubocop/cop/style/when_then.rb