Sha256: a722b69524f6a4d8a5967c78843cf0c8b17eaa9d04eb7f7cf120739aedccee23
Contents?: true
Size: 959 Bytes
Versions: 16
Compression:
Stored size: 959 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 < Cop MSG = 'Avoid the use of Perl-style backrefs.' def on_nth_ref(node) add_offense(node) end def autocorrect(node) lambda 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
16 entries across 16 versions & 3 rubygems