Skip to content

Commit 4e573c1

Browse files
committed
(PUP-11993) Style/RegexpLiteral
This commit enables the Style/RegexpLiteral cop and fixes 84 autocorrectable offenses.
1 parent 03bf4a7 commit 4e573c1

File tree

41 files changed

+78
-84
lines changed

Some content is hidden

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

41 files changed

+78
-84
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,6 @@ Style/RedundantSelfAssignment:
679679
Exclude:
680680
- 'lib/puppet/context.rb'
681681

682-
# This cop supports safe auto-correction (--auto-correct).
683-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
684-
# SupportedStyles: slashes, percent_r, mixed
685-
Style/RegexpLiteral:
686-
Enabled: false
687-
688682
# This cop supports safe auto-correction (--auto-correct).
689683
Style/RescueModifier:
690684
Exclude:

lib/puppet/defaults.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def self.initialize_default_settings!(settings)
650650
:http_proxy_password =>{
651651
:default => "none",
652652
:hook => proc do |value|
653-
if value =~ /[@!# \/]/
653+
if value =~ %r{[@!# /]}
654654
raise "Passwords set in the http_proxy_password setting must be valid as part of a URL, and any reserved characters must be URL-encoded. We received: #{value}"
655655
end
656656
end,

lib/puppet/file_serving/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def split_path(request)
5656

5757
mount_name, path = request.key.split(File::Separator, 2)
5858

59-
raise(ArgumentError, _("Cannot find file: Invalid mount '%{mount_name}'") % { mount_name: mount_name }) unless mount_name =~ %r{^[-\w]+$}
59+
raise(ArgumentError, _("Cannot find file: Invalid mount '%{mount_name}'") % { mount_name: mount_name }) unless mount_name =~ /^[-\w]+$/
6060
raise(ArgumentError, _("Cannot find file: Invalid relative path '%{path}'") % { path: path }) if path and path.split('/').include?('..')
6161

6262
mount = find_mount(mount_name, request.environment)
@@ -71,7 +71,7 @@ def split_path(request)
7171
path = nil
7272
elsif path
7373
# Remove any double slashes that might have occurred
74-
path = path.gsub(/\/+/, "/")
74+
path = path.gsub(%r{/+}, "/")
7575
end
7676

7777
return mount, path

lib/puppet/file_serving/fileset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.merge(*filesets)
2929
def initialize(path, options = {})
3030
if Puppet::Util::Platform.windows?
3131
# REMIND: UNC path
32-
path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
32+
path = path.chomp(File::SEPARATOR) unless path =~ %r{^[A-Za-z]:/$}
3333
else
3434
path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
3535
end

lib/puppet/file_serving/mount.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def find(path, options)
1818

1919
# Create our object. It must have a name.
2020
def initialize(name)
21-
unless name =~ %r{^[-\w]+$}
21+
unless name =~ /^[-\w]+$/
2222
raise ArgumentError, _("Invalid mount name format '%{name}'") % { name: name }
2323
end
2424

lib/puppet/file_system/path_pattern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PathPattern
88
class InvalidPattern < Puppet::Error; end
99

1010
DOTDOT = '..'
11-
ABSOLUTE_UNIX = /^\//
11+
ABSOLUTE_UNIX = %r{^/}
1212
ABSOLUTE_WINDOWS = /^[a-z]:/i
1313
CURRENT_DRIVE_RELATIVE_WINDOWS = /^\\/
1414

lib/puppet/functions/abs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def on_string(x)
5353
# version of this function.
5454
#
5555
case x
56-
when %r{^-?(?:\d+)(?:\.\d+){1}$}
56+
when /^-?(?:\d+)(?:\.\d+){1}$/
5757
x.to_f.abs
58-
when %r{^-?\d+$}
58+
when /^-?\d+$/
5959
x.to_i.abs
6060
else
6161
raise(ArgumentError, 'abs(): Requires float or integer to work with - was given non decimal string')

lib/puppet/functions/max.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def on_string(*args)
146146
assert_arg_count(args)
147147

148148
args.max do |a, b|
149-
if a.to_s =~ %r{\A^-?\d+([._eE]\d+)?\z} && b.to_s =~ %r{\A-?\d+([._eE]\d+)?\z}
149+
if a.to_s =~ /\A^-?\d+([._eE]\d+)?\z/ && b.to_s =~ /\A-?\d+([._eE]\d+)?\z/
150150
Puppet.warn_once('deprecations', 'max_function_numeric_coerce_string',
151151
_("The max() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
152152
a.to_f <=> b.to_f
@@ -232,7 +232,7 @@ def on_any(*args)
232232
args.max do |a, b|
233233
as = a.to_s
234234
bs = b.to_s
235-
if as =~ %r{\A^-?\d+([._eE]\d+)?\z} && bs =~ %r{\A-?\d+([._eE]\d+)?\z}
235+
if as =~ /\A^-?\d+([._eE]\d+)?\z/ && bs =~ /\A-?\d+([._eE]\d+)?\z/
236236
Puppet.warn_once('deprecations', 'max_function_numeric_coerce_string',
237237
_("The max() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
238238
a.to_f <=> b.to_f

lib/puppet/functions/min.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def on_string(*args)
145145
assert_arg_count(args)
146146

147147
args.min do |a, b|
148-
if a.to_s =~ %r{\A^-?\d+([._eE]\d+)?\z} && b.to_s =~ %r{\A-?\d+([._eE]\d+)?\z}
148+
if a.to_s =~ /\A^-?\d+([._eE]\d+)?\z/ && b.to_s =~ /\A-?\d+([._eE]\d+)?\z/
149149
Puppet.warn_once('deprecations', 'min_function_numeric_coerce_string',
150150
_("The min() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
151151
a.to_f <=> b.to_f
@@ -231,7 +231,7 @@ def on_any(*args)
231231
args.min do |a, b|
232232
as = a.to_s
233233
bs = b.to_s
234-
if as =~ %r{\A^-?\d+([._eE]\d+)?\z} && bs =~ %r{\A-?\d+([._eE]\d+)?\z}
234+
if as =~ /\A^-?\d+([._eE]\d+)?\z/ && bs =~ /\A-?\d+([._eE]\d+)?\z/
235235
Puppet.warn_once('deprecations', 'min_function_numeric_coerce_string',
236236
_("The min() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
237237
a.to_f <=> b.to_f

lib/puppet/http/proxy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def self.no_proxy?(dest)
5656
# If this no_proxy entry specifies a port, we want to match it against
5757
# the destination port. Otherwise just match hosts.
5858
if port
59-
no_proxy_regex = %r{#{host}:#{port}$}
59+
no_proxy_regex = /#{host}:#{port}$/
6060
dest_string = "#{dest.host}:#{dest.port}"
6161
else
62-
no_proxy_regex = %r{#{host}$}
62+
no_proxy_regex = /#{host}$/
6363
dest_string = "#{dest.host}"
6464
end
6565

0 commit comments

Comments
 (0)