Sha256: 588fff1f0ef5f982aa5b0fe903aef396c76ce00cbf4f6013176ce0163354955a

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

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
      #     do_something
      #   when baz
      #   end
      #
      # @example
      #
      #   # good
      #   case condition
      #   when foo
      #     do_something
      #   when bar
      #     nil
      #   end
      #
      # @example AllowComments: true (default)
      #
      #   # good
      #   case condition
      #   when foo
      #     do_something
      #   when bar
      #     # noop
      #   end
      #
      # @example AllowComments: false
      #
      #   # bad
      #   case condition
      #   when foo
      #     do_something
      #   when bar
      #     # do nothing
      #   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
            next if cop_config['AllowComments'] && comment_lines?(node)

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

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/empty_when.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.87.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.87.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.86.0 lib/rubocop/cop/lint/empty_when.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/empty_when.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/empty_when.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.85.1 lib/rubocop/cop/lint/empty_when.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.85.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.84.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-0.83.0 lib/rubocop/cop/lint/empty_when.rb