Sha256: 78fe9dfc7eb001e53dd5a388c9ca882267a4b8b5f533f31e2a156baf8f171d54

Contents?: true

Size: 551 Bytes

Versions: 7

Compression:

Stored size: 551 Bytes

Contents

# frozen_string_literal: true

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.'.freeze

        def on_when(node)
          return if node.multiline? || node.then? || !node.body

          add_offense(node, :begin)
        end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.50.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.49.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.49.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.48.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.48.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.47.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.47.0 lib/rubocop/cop/style/when_then.rb