Sha256: 05698aa0fad1bfba3d73f5a3d3ea961cd1add845ee39e6f6eda311fc9fa57ed6

Contents?: true

Size: 752 Bytes

Versions: 47

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for the presence of `when` branches without a body.
      #
      # @example
      #
      #   # bad
      #
      #   case foo
      #   when bar then 1
      #   when baz then # nothing
      #   end
      #
      # @example
      #
      #   # good
      #
      #   case foo
      #   when bar then 1
      #   when baz then 2
      #   end
      class EmptyWhen < Cop
        MSG = 'Avoid `when` branches without a body.'

        def on_case(node)
          node.each_when do |when_node|
            next if when_node.body

            add_offense(when_node, location: when_node.source_range)
          end
        end
      end
    end
  end
end

Version data entries

47 entries across 28 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/lint/empty_when.rb
rubocop-0.82.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.81.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.80.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.80.0 lib/rubocop/cop/lint/empty_when.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/empty_when.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/empty_when.rb
rubocop-0.79.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.78.0 lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/empty_when.rb
rubocop-0.77.0 lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/empty_when.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/empty_when.rb