Sha256: 6bd356547b43d0892e895a178617fa110e0b2caa22d6908780d58bde7be0395c

Contents?: true

Size: 609 Bytes

Versions: 10

Compression:

Stored size: 609 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop looks for uses of Perl-style regexp match
      # backreferences like $1, $2, etc.
      class PerlBackrefs < Cop
        MSG = 'Avoid the use of Perl-style backrefs.'

        def on_nth_ref(node)
          add_offense(node, :expression)
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            backref, = *node

            corrector.replace(node.loc.expression,
                              "Regexp.last_match[#{backref}]")
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/perl_backrefs.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.27.1 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.27.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.26.1 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.26.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.25.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.24.1 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.24.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.23.0 lib/rubocop/cop/style/perl_backrefs.rb