Skip to content

Commit e2c3f6a

Browse files
committed
(CONT-801) Autocorrect safe group 7
1 parent 8215008 commit e2c3f6a

19 files changed

+32
-84
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -290,58 +290,6 @@ Style/RedundantArgument:
290290
Exclude:
291291
- 'lib/puppet/provider/file_line/ruby.rb'
292292

293-
# Offense count: 1
294-
# This cop supports safe autocorrection (--autocorrect).
295-
Style/RedundantFileExtensionInRequire:
296-
Exclude:
297-
- 'lib/puppet/functions/to_toml.rb'
298-
299-
# Offense count: 6
300-
# This cop supports safe autocorrection (--autocorrect).
301-
Style/RedundantHeredocDelimiterQuotes:
302-
Exclude:
303-
- 'lib/puppet/parser/functions/convert_base.rb'
304-
- 'lib/puppet/parser/functions/deep_merge.rb'
305-
- 'lib/puppet/parser/functions/getparam.rb'
306-
- 'lib/puppet/parser/functions/loadjson.rb'
307-
- 'lib/puppet/parser/functions/loadyaml.rb'
308-
- 'lib/puppet/parser/functions/merge.rb'
309-
310-
# Offense count: 1
311-
# This cop supports safe autocorrection (--autocorrect).
312-
Style/RedundantParentheses:
313-
Exclude:
314-
- 'lib/puppet/parser/functions/pw_hash.rb'
315-
316-
# Offense count: 41
317-
# This cop supports safe autocorrection (--autocorrect).
318-
Style/RedundantRegexpEscape:
319-
Exclude:
320-
- 'lib/puppet/parser/functions/loadjson.rb'
321-
- 'lib/puppet/parser/functions/loadyaml.rb'
322-
- 'lib/puppet/parser/functions/range.rb'
323-
- 'lib/puppet/parser/functions/values_at.rb'
324-
- 'spec/functions/load_module_metadata_spec.rb'
325-
- 'spec/functions/loadjson_spec.rb'
326-
- 'spec/functions/validate_cmd_spec.rb'
327-
328-
# Offense count: 4
329-
# This cop supports safe autocorrection (--autocorrect).
330-
Style/RedundantStringEscape:
331-
Exclude:
332-
- 'lib/puppet/type/file_line.rb'
333-
334-
# Offense count: 4
335-
# This cop supports safe autocorrection (--autocorrect).
336-
# Configuration parameters: EnforcedStyle.
337-
# SupportedStyles: implicit, explicit
338-
Style/RescueStandardError:
339-
Exclude:
340-
- 'lib/puppet/functions/stdlib/crc32.rb'
341-
- 'lib/puppet/functions/stdlib/sha256.rb'
342-
- 'lib/puppet/parser/functions/any2bool.rb'
343-
- 'spec/spec_helper.rb'
344-
345293
# Offense count: 1
346294
# This cop supports unsafe autocorrection (--autocorrect-all).
347295
Style/SelectByRegexp:

lib/puppet/functions/stdlib/crc32.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
def crc32(my_data)
2727
Zlib.crc32(my_data.unwrap.to_s).to_s(16).downcase
28-
rescue
28+
rescue StandardError
2929
Zlib.crc32(my_data.to_s).to_s(16).downcase
3030
end
3131
end

lib/puppet/functions/stdlib/sha256.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
def sha256(my_data)
2222
Digest::SHA256.hexdigest(my_data.unwrap.to_s)
23-
rescue
23+
rescue StandardError
2424
Digest::SHA256.hexdigest(my_data.to_s)
2525
end
2626
end

lib/puppet/functions/to_toml.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative '../../puppet_x/stdlib/toml_dumper.rb'
3+
require_relative '../../puppet_x/stdlib/toml_dumper'
44

55
# @summary Convert a data structure and output to TOML.
66
Puppet::Functions.create_function(:to_toml) do

lib/puppet/parser/functions/any2bool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module Puppet::Parser::Functions
3535

3636
valid_float = begin
3737
!!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
38-
rescue
38+
rescue StandardError
3939
false
4040
end
4141

lib/puppet/parser/functions/convert_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# convert_base.rb
55
#
66
module Puppet::Parser::Functions
7-
newfunction(:convert_base, type: :rvalue, arity: 2, doc: <<-'DOC') do |args|
7+
newfunction(:convert_base, type: :rvalue, arity: 2, doc: <<-DOC) do |args|
88
@summary
99
Converts a given integer or base 10 string representing an integer to a
1010
specified base, as a string.

lib/puppet/parser/functions/deep_merge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# deep_merge.rb
55
#
66
module Puppet::Parser::Functions
7-
newfunction(:deep_merge, type: :rvalue, doc: <<-'DOC') do |args|
7+
newfunction(:deep_merge, type: :rvalue, doc: <<-DOC) do |args|
88
@summary
99
Recursively merges two or more hashes together and returns the resulting hash.
1010

lib/puppet/parser/functions/getparam.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Test whether a given class or definition is defined
44
require 'puppet/parser/functions'
55

6-
Puppet::Parser::Functions.newfunction(:getparam, type: :rvalue, doc: <<-'DOC'
6+
Puppet::Parser::Functions.newfunction(:getparam, type: :rvalue, doc: <<-DOC
77
@summary
88
Returns the value of a resource's parameter.
99

lib/puppet/parser/functions/loadjson.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
module Puppet::Parser::Functions
8-
newfunction(:loadjson, type: :rvalue, arity: -2, doc: <<-'DOC') do |args|
8+
newfunction(:loadjson, type: :rvalue, arity: -2, doc: <<-DOC) do |args|
99
@summary
1010
Load a JSON file containing an array, string, or hash, and return the data
1111
in the corresponding native data type.
@@ -30,12 +30,12 @@ module Puppet::Parser::Functions
3030
begin
3131
if args[0].start_with?('http://', 'https://')
3232
http_options = {}
33-
if (match = args[0].match(%r{(http\://|https\://)(.*):(.*)@(.*)}))
33+
if (match = args[0].match(%r{(http://|https://)(.*):(.*)@(.*)}))
3434
# If URL is in the format of https://username:password@example.local/my_hash.yaml
3535
protocol, username, password, path = match.captures
3636
url = "#{protocol}#{path}"
3737
http_options[:http_basic_authentication] = [username, password]
38-
elsif (match = args[0].match(%r{(http\:\/\/|https\:\/\/)(.*)@(.*)}))
38+
elsif (match = args[0].match(%r{(http://|https://)(.*)@(.*)}))
3939
# If URL is in the format of https://username@example.local/my_hash.yaml
4040
protocol, username, path = match.captures
4141
url = "#{protocol}#{path}"

lib/puppet/parser/functions/loadyaml.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# loadyaml.rb
55
#
66
module Puppet::Parser::Functions
7-
newfunction(:loadyaml, type: :rvalue, arity: -2, doc: <<-'DOC') do |args|
7+
newfunction(:loadyaml, type: :rvalue, arity: -2, doc: <<-DOC) do |args|
88
@summary
99
Load a YAML file containing an array, string, or hash, and return the data
1010
in the corresponding native data type.
@@ -31,11 +31,11 @@ module Puppet::Parser::Functions
3131
if args[0].start_with?('http://', 'https://')
3232
username = ''
3333
password = ''
34-
if (match = args[0].match(%r{(http\://|https\://)(.*):(.*)@(.*)}))
34+
if (match = args[0].match(%r{(http://|https://)(.*):(.*)@(.*)}))
3535
# If URL is in the format of https://username:password@example.local/my_hash.yaml
3636
protocol, username, password, path = match.captures
3737
url = "#{protocol}#{path}"
38-
elsif (match = args[0].match(%r{(http\:\/\/|https\:\/\/)(.*)@(.*)}))
38+
elsif (match = args[0].match(%r{(http://|https://)(.*)@(.*)}))
3939
# If URL is in the format of https://username@example.local/my_hash.yaml
4040
protocol, username, path = match.captures
4141
url = "#{protocol}#{path}"

lib/puppet/parser/functions/merge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# merge.rb
55
#
66
module Puppet::Parser::Functions
7-
newfunction(:merge, type: :rvalue, doc: <<-'DOC') do |args|
7+
newfunction(:merge, type: :rvalue, doc: <<-DOC) do |args|
88
@summary
99
Merges two or more hashes together and returns the resulting hash.
1010

lib/puppet/parser/functions/pw_hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
# handle weak implementations of String#crypt
7878
# dup the string to get rid of frozen status for testing
79-
if ('test'.dup).crypt('$1$1') == '$1$1$Bp8CU9Oujr9SSEw53WV6G.'
79+
if 'test'.dup.crypt('$1$1') == '$1$1$Bp8CU9Oujr9SSEw53WV6G.'
8080
password.crypt(salt)
8181
else
8282
# JRuby < 1.7.17

lib/puppet/parser/functions/range.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module Puppet::Parser::Functions
5959
else # arguments.size == 1
6060
value = arguments[0]
6161

62-
m = value.match(%r{^(\w+)(\.\.\.?|\-)(\w+)$})
62+
m = value.match(%r{^(\w+)(\.\.\.?|-)(\w+)$})
6363
if m
6464
start = m[1]
6565
stop = m[3]

lib/puppet/parser/functions/values_at.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module Puppet::Parser::Functions
5353

5454
indices.each do |i|
5555
i = i.to_s
56-
m = i.match(%r{^(\d+)(\.\.\.?|\-)(\d+)$})
56+
m = i.match(%r{^(\d+)(\.\.\.?|-)(\d+)$})
5757
if m
5858
start = m[1].to_i
5959
stop = m[3].to_i
@@ -64,8 +64,8 @@ module Puppet::Parser::Functions
6464
raise(Puppet::ParseError, 'values_at(): Stop index in given indices range exceeds array size') if stop > array.size - 1 # First element is at index 0 is it not?
6565

6666
range = case type
67-
when %r{^(\.\.|\-)$} then (start..stop)
68-
when %r{^(\.\.\.)$} then (start...stop) # Exclusive of last element ...
67+
when %r{^(\.\.|-)$} then (start..stop)
68+
when %r{^(\.\.\.)$} then (start...stop) # Exclusive of last element ...
6969
end
7070

7171
range.each { |i| indices_list << i.to_i } # rubocop:disable Lint/ShadowingOuterLocalVariable : Value is meant to be shadowed

lib/puppet/type/file_line.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
ensure => present,
3333
path => '/etc/bashrc',
3434
line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
35-
match => '^export\ HTTP_PROXY\=',
35+
match => '^export HTTP_PROXY=',
3636
}
3737
```
3838
@@ -50,7 +50,7 @@
5050
file_line { 'bashrc_proxy':
5151
ensure => absent,
5252
path => '/etc/bashrc',
53-
match => '^export\ HTTP_PROXY\=',
53+
match => '^export HTTP_PROXY=',
5454
match_for_absence => true,
5555
}
5656
```

spec/functions/load_module_metadata_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
before :each do
1212
# In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock
1313
allow(File).to receive(:read).with(anything, anything).and_call_original
14-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
15-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
14+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
15+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1616
# Additional modules used by litmus which are identified while running these dues to being in fixtures
17-
allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, encoding: 'utf-8')
17+
allow(File).to receive(:read).with(%r{/(provision|puppet_agent|facts)/metadata.json}, encoding: 'utf-8')
1818
end
1919

2020
context 'when calling with valid utf8 and double byte character arguments' do
2121
before :each do
22-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
22+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}, encoding: 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
2323
この文字"}')
24-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
24+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
2525
この文字"}')
2626
end
2727

spec/functions/loadjson_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
before :each do
1111
# In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock
1212
allow(File).to receive(:read).with(anything, anything).and_call_original
13-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
14-
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
13+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
14+
allow(File).to receive(:read).with(%r{/(stdlib|test)/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1515
# Additional modules used by litmus which are identified while running these dues to being in fixtures
16-
allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, encoding: 'utf-8')
16+
allow(File).to receive(:read).with(%r{/(provision|puppet_agent|facts)/metadata.json}, encoding: 'utf-8')
1717
end
1818

1919
context 'when a non-existing file is specified' do

spec/functions/validate_cmd_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
context 'with % placeholder' do
3232
it {
3333
expect(subject).to run
34-
.with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \S+ \/no\/such\/file' returned 1:.*(cannot touch|o such file or)})
34+
.with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \S+ /no/such/file' returned 1:.*(cannot touch|o such file or)})
3535
}
3636

3737
it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
@@ -40,7 +40,7 @@
4040
context 'without % placeholder' do
4141
it {
4242
expect(subject).to run
43-
.with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \/no\/such\/file \S+' returned 1:.*(cannot touch|o such file or)})
43+
.with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} /no/such/file \S+' returned 1:.*(cannot touch|o such file or)})
4444
}
4545

4646
it { is_expected.to run.with_params('', "#{touch} /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
begin
2828
default_facts.merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true))
29-
rescue => e
29+
rescue StandardError => e
3030
RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
3131
end
3232
end

0 commit comments

Comments
 (0)