Sha256: 77f710befaee6048bf8bab5d02abb7234e88de6588f839fc9430dc08d776bf56

Contents?: true

Size: 790 Bytes

Versions: 49

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for *when;* uses in *case* expressions.
      #
      # @example
      #   # bad
      #   case foo
      #   when 1; 'baz'
      #   when 2; 'bar'
      #   end
      #
      #   # good
      #   case foo
      #   when 1 then 'baz'
      #   when 2 then 'bar'
      #   end
      class WhenThen < Cop
        MSG = 'Do not use `when x;`. Use `when x then` instead.'

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

          add_offense(node, location: :begin)
        end

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

Version data entries

49 entries across 30 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/when_then.rb
rubocop-0.84.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.83.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.82.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.81.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.80.1 lib/rubocop/cop/style/when_then.rb
rubocop-0.80.0 lib/rubocop/cop/style/when_then.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/when_then.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/when_then.rb
rubocop-0.79.0 lib/rubocop/cop/style/when_then.rb
rubocop-0.78.0 lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/when_then.rb
rubocop-0.77.0 lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/when_then.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/style/when_then.rb