Sha256: 01994b95ff716bd11a37a8e5f2b14e8591884f815e72624895856d4e2d0f8cd9

Contents?: true

Size: 609 Bytes

Versions: 4

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_offence(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

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.18.1 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.18.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.17.0 lib/rubocop/cop/style/perl_backrefs.rb
rubocop-0.16.0 lib/rubocop/cop/style/perl_backrefs.rb