Sha256: 92fcb2d22f707cdcd67103f699844453b9cc5d4bee42c713341c7245ce672a02

Contents?: true

Size: 1.19 KB

Versions: 69

Compression:

Stored size: 1.19 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 < Base
        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)
          end
        end
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 8 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_when.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.26.1 lib/rubocop/cop/lint/empty_when.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.26.0 lib/rubocop/cop/lint/empty_when.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.25.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.25.0 lib/rubocop/cop/lint/empty_when.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.24.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.24.0 lib/rubocop/cop/lint/empty_when.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.23.0 lib/rubocop/cop/lint/empty_when.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.22.3 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.22.2 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.22.1 lib/rubocop/cop/lint/empty_when.rb