Skip to content

Commit 9c208c9

Browse files
committed
(PUP-11993) Style/RedundantRegexpEscape
This commit enables the Style/RedundantRegexpEscape cop and fixes 27 autocorrectable offenses.
1 parent f30bc09 commit 9c208c9

File tree

20 files changed

+22
-26
lines changed

20 files changed

+22
-26
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,6 @@ Style/RedundantFetchBlock:
668668
Style/RedundantInterpolation:
669669
Enabled: false
670670

671-
# This cop supports safe auto-correction (--auto-correct).
672-
Style/RedundantRegexpEscape:
673-
Enabled: false
674-
675671
# This cop supports safe auto-correction (--auto-correct).
676672
# Configuration parameters: AllowMultipleReturnValues.
677673
Style/RedundantReturn:

lib/puppet/face/help.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def horribly_extract_summary_from(appname)
208208
# formatted. If we can't match the pattern we expect we return the empty
209209
# string to ensure we don't blow up in the summary. --daniel 2011-04-11
210210
while line = help.shift do # rubocop:disable Lint/AssignmentInCondition
211-
md = /^puppet-#{appname}\([^\)]+\) -- (.*)$/.match(line)
211+
md = /^puppet-#{appname}\([^)]+\) -- (.*)$/.match(line)
212212
if md
213213
return md[1]
214214
end

lib/puppet/pops/loader/ruby_data_type_instantiator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Puppet::Pops::Loader::RubyDataTypeInstantiator
1515
# @return [Puppet::Pops::Types::PAnyType] - an instantiated data type associated with the given loader
1616
#
1717
def self.create(loader, typed_name, source_ref, ruby_code_string)
18-
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet\:\:DataTypes\.create_type/
18+
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet::DataTypes\.create_type/
1919
raise ArgumentError, _("The code loaded from %{source_ref} does not seem to be a Puppet 5x API data type - no create_type call.") % { source_ref: source_ref }
2020
end
2121

lib/puppet/pops/loader/ruby_function_instantiator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Puppet::Pops::Loader::RubyFunctionInstantiator
1515
# @return [Puppet::Pops::Functions.Function] - an instantiated function with global scope closure associated with the given loader
1616
#
1717
def self.create(loader, typed_name, source_ref, ruby_code_string)
18-
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet\:\:Functions\.create_function/
18+
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet::Functions\.create_function/
1919
raise ArgumentError, _("The code loaded from %{source_ref} does not seem to be a Puppet 4x API function - no create_function call.") % { source_ref: source_ref }
2020
end
2121

lib/puppet/pops/lookup/interpolation.rb

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

lib/puppet/pops/lookup/sub_lookup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Puppet::Pops
44
module Lookup
55
module SubLookup
6-
SPECIAL = /['"\.]/
6+
SPECIAL = /['".]/
77

88
# Split key into segments. A segment may be a quoted string (both single and double quotes can
99
# be used) and the segment separator is the '.' character. Whitespace will be trimmed off on

lib/puppet/pops/parser/heredoc_support.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module HeredocSupport
88
# Pattern for heredoc `@(endtag[:syntax][/escapes])
99
# Produces groups for endtag (group 1), syntax (group 2), and escapes (group 3)
1010
#
11-
PATTERN_HEREDOC = %r{@\(([^:/\r\n\)]+)(?::[[:blank:]]*([a-z][a-zA-Z0-9_+]+)[[:blank:]]*)?(?:/((?:\w|[$])*)[[:blank:]]*)?\)}
11+
PATTERN_HEREDOC = %r{@\(([^:/\r\n)]+)(?::[[:blank:]]*([a-z][a-zA-Z0-9_+]+)[[:blank:]]*)?(?:/((?:\w|[$])*)[[:blank:]]*)?\)}
1212

1313
def heredoc
1414
scn = @scanner
@@ -81,7 +81,7 @@ def heredoc
8181
# that terminates the heredoc is found.
8282

8383
# (Endline in EBNF form): WS* ('|' WS*)? ('-' WS*)? endtag WS* \r? (\n|$)
84-
endline_pattern = /([[:blank:]]*)(?:([|])[[:blank:]]*)?(?:(\-)[[:blank:]]*)?#{Regexp.escape(endtag)}[[:blank:]]*\r?(?:\n|\z)/
84+
endline_pattern = /([[:blank:]]*)(?:([|])[[:blank:]]*)?(?:(-)[[:blank:]]*)?#{Regexp.escape(endtag)}[[:blank:]]*\r?(?:\n|\z)/
8585
lines = []
8686
until scn.eos? do
8787
one_line = scn.scan_until(/(?:\n|\z)/)

lib/puppet/provider/package/appdmg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def self.installpkgdmg(source, name)
5757
cached_source = source
5858
tmpdir = Dir.mktmpdir
5959
begin
60-
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
60+
if %r{\A[A-Za-z][A-Za-z0-9+\-.]*://} =~ cached_source
6161
cached_source = File.join(tmpdir, name)
6262
begin
6363
curl "-o", cached_source, "-C", "-", "-L", "-s", "--url", source

lib/puppet/provider/package/aptrpm.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def latest
5353
if output =~ /Versions:\s*\n((\n|.)+)^$/
5454
versions = Regexp.last_match(1)
5555
available_versions = versions.split(/\n/).filter_map { |version|
56-
if version =~ /^([^\(]+)\(/
56+
if version =~ /^([^(]+)\(/
5757
Regexp.last_match(1)
5858
else
5959
self.warning _("Could not match version '%{version}'") % { version: version }

lib/puppet/provider/package/pkgdmg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def self.installpkgdmg(source, name)
8585
tmpdir = Dir.mktmpdir
8686
ext = /(\.dmg|\.pkg)$/i.match(source)[0]
8787
begin
88-
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
88+
if %r{\A[A-Za-z][A-Za-z0-9+\-.]*://} =~ cached_source
8989
cached_source = File.join(tmpdir, "#{name}#{ext}")
9090
args = ["-o", cached_source, "-C", "-", "-L", "-s", "--fail", "--url", source]
9191
if http_proxy_host and http_proxy_port

0 commit comments

Comments
 (0)