Sha256: 5a59645ac1121f43f2fbb94b456ce7d2ec27dba2ca2b4da8f1e79096a00ad77f

Contents?: true

Size: 1.24 KB

Versions: 16

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

16 entries across 16 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_in_pattern.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.26.1 lib/rubocop/cop/lint/empty_in_pattern.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.26.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.25.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.25.0 lib/rubocop/cop/lint/empty_in_pattern.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.24.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.24.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.23.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.22.3 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.22.2 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.22.1 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.22.0 lib/rubocop/cop/lint/empty_in_pattern.rb
rubocop-1.21.0 lib/rubocop/cop/lint/empty_in_pattern.rb