Sha256: 56cbfb665b5940a30a08d5e779817c9cd1281e89965e6d1c863dcb8a9ed6a005

Contents?: true

Size: 888 Bytes

Versions: 11

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Do not mix named captures and numbered captures in a Regexp literal
      # because numbered capture is ignored if they're mixed.
      # Replace numbered captures with non-capturing groupings or
      # named captures.
      #
      #   # bad
      #   /(?<foo>FOO)(BAR)/
      #
      #   # good
      #   /(?<foo>FOO)(?<bar>BAR)/
      #
      #   # good
      #   /(?<foo>FOO)(?:BAR)/
      #
      #   # good
      #   /(FOO)(BAR)/
      #
      class MixedRegexpCaptureTypes < Base
        MSG = 'Do not mix named captures and numbered captures ' \
              'in a Regexp literal.'

        def on_regexp(node)
          return if node.each_capture(named: false).none?
          return if node.each_capture(named: true).none?

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-0.92.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-0.91.1 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-0.91.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.90.0/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-0.90.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb