Sha256: 9980bf79b582899a5787f47a4d6f5f7d5c3e4290306d95d2d55d44100ca7dd92
Contents?: true
Size: 868 Bytes
Versions: 24
Compression:
Stored size: 868 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Style # This cop looks for uses of Perl-style regexp match # backreferences like $1, $2, etc. # # @example # # bad # puts $1 # # # good # puts Regexp.last_match(1) class PerlBackrefs < Base extend AutoCorrector MSG = 'Avoid the use of Perl-style backrefs.' def on_nth_ref(node) add_offense(node) do |corrector| backref, = *node parent_type = node.parent ? node.parent.type : nil if %i[dstr xstr regexp].include?(parent_type) corrector.replace(node, "{Regexp.last_match(#{backref})}") else corrector.replace(node, "Regexp.last_match(#{backref})") end end end end end end end
Version data entries
24 entries across 24 versions & 3 rubygems