Sha256: 89b53ad951755d18486ec0327568abcf7370a6f6fb5a0774e688effa73b53a2b

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 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
        include CommentsHelp

        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
            next if cop_config['AllowComments'] && contains_comments?(branch)

            add_offense(branch)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-1.29.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.29.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.28.2 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.28.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.28.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.27.0 lib/rubocop/cop/lint/empty_in_pattern.rb