Sha256: 0b0aef769060bdf47e835b3e706238db0e23056272b20aefbdab5ccbafb98984

Contents?: true

Size: 608 Bytes

Versions: 3

Compression:

Stored size: 608 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)
          convention(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

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.15.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.14.1 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.14.0 lib/rubocop/cop/style/perl_backrefs.rb