Sha256: f17a1a3bb9e56fb9af05074ed353148e9a3b945a212bdf0bd54bb5a00e7b2f2d

Contents?: true

Size: 549 Bytes

Versions: 9

Compression:

Stored size: 549 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)
          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

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/when_then.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/when_then.rb
rubocop-0.27.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.26.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.26.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.25.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.24.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.24.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.23.0 lib/rubocop/cop/style/when_then.rb