Sha256: 9b24cc4d3ef6e45d7f8709122a7188935c1350e04a1d0b17bfda08a5b7040622

Contents?: true

Size: 613 Bytes

Versions: 4

Compression:

Stored size: 613 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
        end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.12.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.11.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.11.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.10.0 lib/rubocop/cop/style/when_then.rb