Sha256: 27b4430460c1d6922bb68abddb5266abcf53582d1903a2a101571141737a8a58

Contents?: true

Size: 556 Bytes

Versions: 3

Compression:

Stored size: 556 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_offence(:convention, node.loc.begin, MSG)
            do_autocorrect(node)
          end

          super
        end

        def autocorrect_action(node)
          replace(node.loc.begin, ' then')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rubocop-0.9.1 lib/rubocop/cop/style/when_then.rb
sabat-rubocop-0.9.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.9.0 lib/rubocop/cop/style/when_then.rb