Sha256: 9ab1e4400fdc09be5bf67044befd537e41e5e5d2e133e59330988bba7b3c80c1

Contents?: true

Size: 504 Bytes

Versions: 9

Compression:

Stored size: 504 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)
          ->(corrector) { corrector.replace(node.loc.begin, ' then') }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.35.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.34.2 lib/rubocop/cop/style/when_then.rb
rubocop-0.34.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.34.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.33.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.32.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.32.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.31.0 lib/rubocop/cop/style/when_then.rb