Skip to content

Commit d6adaf7

Browse files
committed
(PUP-11993) Style/PerlBackrefs
This commit enables the Style/PerlBackrefs cop and fixes 137 autocorrectable offenses.
1 parent b09ca83 commit d6adaf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+105
-109
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,6 @@ Style/NumericPredicate:
640640
Style/OptionalBooleanParameter:
641641
Enabled: false
642642

643-
# This cop supports safe auto-correction (--auto-correct).
644-
Style/PerlBackrefs:
645-
Enabled: false
646-
647643
# This cop supports unsafe auto-correction (--auto-correct-all).
648644
# Configuration parameters: EnforcedStyle.
649645
# SupportedStyles: short, verbose

lib/puppet/application/describe.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def wrap(txt, opts)
2020

2121
while work.length > textLen
2222
if work =~ patt
23-
res << $1
24-
work.slice!(0, $MATCH.length)
23+
res << ::Regexp.last_match(1)
24+
work.slice!(0, ::Regexp.last_match(0).length)
2525
else
2626
res << work.slice!(0, textLen)
2727
end
@@ -43,7 +43,7 @@ def scrub(text)
4343
# If we can match an indentation, then just remove that same level of
4444
# indent from every line.
4545
if text =~ /^(\s+)/
46-
indent = $1
46+
indent = ::Regexp.last_match(1)
4747
return text.gsub(/^#{indent}/, '')
4848
else
4949
return text

lib/puppet/application/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def parse_args(args)
207207
params = {}
208208
args.each do |setting|
209209
if setting =~ /^(\w+)=(.+)$/
210-
params[$1] = $2
210+
params[::Regexp.last_match(1)] = ::Regexp.last_match(2)
211211
else
212212
raise _("Invalid parameter setting %{setting}") % { setting: setting }
213213
end

lib/puppet/file_serving/configuration/parser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def parse
2525
when /^\s*#/; next # skip comments
2626
when /^\s*$/; next # skip blank lines
2727
when /\[([-\w]+)\]/
28-
mount = newmount($1)
28+
mount = newmount(::Regexp.last_match(1))
2929
when /^\s*(\w+)\s+(.+?)(\s*#.*)?$/
30-
var = $1
31-
value = $2
30+
var = ::Regexp.last_match(1)
31+
value = ::Regexp.last_match(2)
3232
value.strip!
3333
raise(ArgumentError, _("Fileserver configuration file does not use '=' as a separator")) if value =~ /^=/
3434

lib/puppet/file_serving/mount/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def expand(path, node = nil)
100100
end
101101

102102
path.gsub(/%(.)/) do |v|
103-
key = $1
103+
key = ::Regexp.last_match(1)
104104
if key == "%"
105105
"%"
106106
else

lib/puppet/functions/defined.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def is_defined(scope, *vals) # rubocop:disable Naming/PredicateName
112112
case val
113113
when String
114114
if val =~ /^\$(.+)$/
115-
scope.exist?($1)
115+
scope.exist?(Regexp.last_match(1))
116116
else
117117
case val
118118
when ''

lib/puppet/indirector/terminus.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def model
101101

102102
# Convert a short name to a constant.
103103
def name2const(name)
104-
name.to_s.capitalize.sub(/_(.)/) { |_i| $1.upcase }
104+
name.to_s.capitalize.sub(/_(.)/) { |_i| ::Regexp.last_match(1).upcase }
105105
end
106106

107107
# Register a class, probably autoloaded.

lib/puppet/parser/scope.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ def include?(name)
283283
def exist?(name)
284284
# Note !! ensure the answer is boolean
285285
!!if name =~ /^(.*)::(.+)$/
286-
class_name = $1
287-
variable_name = $2
286+
class_name = ::Regexp.last_match(1)
287+
variable_name = ::Regexp.last_match(2)
288288
return true if class_name == '' && BUILT_IN_VARS.include?(variable_name)
289289

290290
# lookup class, but do not care if it is not evaluated since that will result
@@ -1046,7 +1046,7 @@ def find_defined_resource_type(type)
10461046

10471047
def method_missing(method, *args, &block)
10481048
method.to_s =~ /^function_(.*)$/
1049-
name = $1
1049+
name = ::Regexp.last_match(1)
10501050
super unless name
10511051
super unless Puppet::Parser::Functions.function(name)
10521052
# In odd circumstances, this might not end up defined by the previous

lib/puppet/pops/lookup/hiera_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def configured_data_providers(lookup_invocation, parent_data_provider, use_defau
212212
# Raise a LookupError with a RUNTIME_ERROR issue to prevent this being translated to an evaluation error triggered in the pp file
213213
# where the lookup started
214214
if e.message =~ /^Undefined variable '([^']+)'/
215-
var = $1
215+
var = ::Regexp.last_match(1)
216216
fail(Issues::HIERA_UNDEFINED_VARIABLE, { :name => var }, find_line_matching(/%\{['"]?#{var}['"]?}/))
217217
end
218218
raise e

lib/puppet/pops/lookup/interpolation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def interpolate_string(subject, context, allow_methods)
4949
lookup_invocation = context.is_a?(Invocation) ? context : context.invocation
5050
lookup_invocation.with(:interpolate, subject) do
5151
subject.gsub(/%\{([^\}]*)\}/) do |match|
52-
expr = $1
52+
expr = ::Regexp.last_match(1)
5353
# Leading and trailing spaces inside an interpolation expression are insignificant
5454
expr.strip!
5555
value = nil

0 commit comments

Comments
 (0)