Sha256: e8bb130d249e53f7dd867415a40951327880db293e8b1afb7ab8310f2c27a3be

Contents?: true

Size: 1.22 KB

Versions: 180

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # 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
        include CommentsHelp

        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'] && contains_comments?(when_node)

            add_offense(when_node)
          end
        end
      end
    end
  end
end

Version data entries

180 entries across 173 versions & 17 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/empty_when.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/empty_when.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/empty_when.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/empty_when.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.64.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.63.4 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.63.3 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.63.2 lib/rubocop/cop/lint/empty_when.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.63.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.63.0 lib/rubocop/cop/lint/empty_when.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.62.1 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.62.0 lib/rubocop/cop/lint/empty_when.rb
rubocop-1.61.0 lib/rubocop/cop/lint/empty_when.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/lint/empty_when.rb
rubocop-1.60.2 lib/rubocop/cop/lint/empty_when.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/empty_when.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/empty_when.rb