Sha256: 9534b8172f213e70318e26d6d1ab442cddb439bcd9f6650b18c057ca4c03f571
Contents?: true
Size: 888 Bytes
Versions: 13
Compression:
Stored size: 888 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. class PerlBackrefs < Cop MSG = 'Avoid the use of Perl-style backrefs.'.freeze def on_nth_ref(node) add_offense(node, :expression) end def autocorrect(node) lambda do |corrector| backref, = *node parent_type = node.parent ? node.parent.type : nil if [:dstr, :xstr, :regexp].include?(parent_type) corrector.replace(node.source_range, "{Regexp.last_match(#{backref})}") else corrector.replace(node.source_range, "Regexp.last_match(#{backref})") end end end end end end end
Version data entries
13 entries across 13 versions & 2 rubygems