Sha256: 983ae68785af602bedb78ff7074e224d4e7494342902cb13d0687b964c942e7f

Contents?: true

Size: 909 Bytes

Versions: 69

Compression:

Stored size: 909 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.interpolation?
          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

69 entries across 63 versions & 7 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.44.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.43.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.42.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.41.1 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.41.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.40.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.39.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.38.0 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb
rubocop-1.37.1 lib/rubocop/cop/lint/mixed_regexp_capture_types.rb