Sha256: 056f775b81a7fd23d37a1773f11ac4606eaffd5852a87f118e28df7f8699001c

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for the presence of `in` pattern branches without a body.
      #
      # @example
      #
      #   # bad
      #   case condition
      #   in [a]
      #     do_something
      #   in [a, b]
      #   end
      #
      #   # good
      #   case condition
      #   in [a]
      #     do_something
      #   in [a, b]
      #     nil
      #   end
      #
      # @example AllowComments: true (default)
      #
      #   # good
      #   case condition
      #   in [a]
      #     do_something
      #   in [a, b]
      #     # noop
      #   end
      #
      # @example AllowComments: false
      #
      #   # bad
      #   case condition
      #   in [a]
      #     do_something
      #   in [a, b]
      #     # noop
      #   end
      #
      class EmptyInPattern < Base
        extend TargetRubyVersion

        MSG = 'Avoid `in` branches without a body.'

        minimum_target_ruby_version 2.7

        def on_case_match(node)
          node.in_pattern_branches.each do |branch|
            next if branch.body || cop_config['AllowComments'] && comment_lines?(node)

            add_offense(branch)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rubocop-1.20.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.19.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.19.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.18.4 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.18.3 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.18.2 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.18.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.18.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.17.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.16.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.16.0 lib/rubocop/cop/lint/empty_in_pattern.rb