Skip to content

Commit 8215008

Browse files
committed
(CONT-801) Autocorrect safe group 6
1 parent 19e72dc commit 8215008

Some content is hidden

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

50 files changed

+106
-307
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require:
55
AllCops:
66
DisplayCopNames: true
77
NewCops: enable
8-
TargetRubyVersion: '2.7'
8+
TargetRubyVersion: '2.6'
99
ExtraDetails: true
1010
DisplayStyleGuide: true
1111
Include:

.rubocop_todo.yml

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-05-17 10:10:18 UTC using RuboCop version 1.48.1.
3+
# on 2023-05-17 10:40:49 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -59,7 +59,7 @@ Metrics/AbcSize:
5959
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
6060
# AllowedMethods: refine
6161
Metrics/BlockLength:
62-
Max: 162
62+
Max: 152
6363

6464
# Offense count: 5
6565
# Configuration parameters: AllowedMethods, AllowedPatterns.
@@ -69,7 +69,7 @@ Metrics/CyclomaticComplexity:
6969
# Offense count: 9
7070
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
7171
Metrics/MethodLength:
72-
Max: 37
72+
Max: 35
7373

7474
# Offense count: 4
7575
# Configuration parameters: AllowedMethods, AllowedPatterns.
@@ -105,12 +105,6 @@ Performance/CollectionLiteralInLoop:
105105
Exclude:
106106
- 'lib/puppet/functions/ensure_packages.rb'
107107

108-
# Offense count: 1
109-
# This cop supports unsafe autocorrection (--autocorrect-all).
110-
Performance/MapCompact:
111-
Exclude:
112-
- 'lib/puppet/parser/functions/values_at.rb'
113-
114108
# Offense count: 1
115109
# This cop supports unsafe autocorrection (--autocorrect-all).
116110
# Configuration parameters: AllowRegexpMatch.
@@ -168,7 +162,7 @@ RSpec/MultipleExpectations:
168162
RSpec/MultipleMemoizedHelpers:
169163
Max: 9
170164

171-
# Offense count: 55
165+
# Offense count: 253
172166
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
173167
# SupportedStyles: always, named_only
174168
RSpec/NamedSubject:
@@ -241,26 +235,12 @@ Style/FrozenStringLiteralComment:
241235
- 'spec/type_aliases/http__method_spec.rb'
242236
- 'spec/type_aliases/http__status_spec.rb'
243237

244-
# Offense count: 3
245-
# This cop supports safe autocorrection (--autocorrect).
246-
# Configuration parameters: AllowSplatArgument.
247-
Style/HashConversion:
248-
Exclude:
249-
- 'lib/puppet/functions/to_json_pretty.rb'
250-
- 'lib/puppet/parser/functions/prefix.rb'
251-
- 'lib/puppet/parser/functions/suffix.rb'
252-
253238
# Offense count: 1
254239
# This cop supports unsafe autocorrection (--autocorrect-all).
255240
Style/HashTransformKeys:
256241
Exclude:
257242
- 'lib/puppet/functions/to_json_pretty.rb'
258243

259-
# Offense count: 85
260-
# This cop supports safe autocorrection (--autocorrect).
261-
Style/IfUnlessModifier:
262-
Enabled: false
263-
264244
# Offense count: 4
265245
# This cop supports unsafe autocorrection (--autocorrect-all).
266246
# Configuration parameters: AllowedMethods.
@@ -272,24 +252,19 @@ Style/IfWithBooleanLiteralBranches:
272252
- 'lib/puppet/parser/functions/shuffle.rb'
273253
- 'lib/puppet/provider/file_line/ruby.rb'
274254

275-
# Offense count: 1
276-
# This cop supports safe autocorrection (--autocorrect).
277-
# Configuration parameters: AllowedMethods, AllowedPatterns.
278-
Style/MethodCallWithoutArgsParentheses:
255+
# Offense count: 3
256+
# This cop supports unsafe autocorrection (--autocorrect-all).
257+
Style/MapToHash:
279258
Exclude:
280-
- 'lib/puppet/functions/deprecation.rb'
259+
- 'lib/puppet/functions/to_json_pretty.rb'
260+
- 'lib/puppet/parser/functions/prefix.rb'
261+
- 'lib/puppet/parser/functions/suffix.rb'
281262

282263
# Offense count: 1
283264
Style/MixinUsage:
284265
Exclude:
285266
- 'spec/spec_helper.rb'
286267

287-
# Offense count: 1
288-
# This cop supports safe autocorrection (--autocorrect).
289-
Style/NegatedIfElseCondition:
290-
Exclude:
291-
- 'lib/puppet/parser/functions/pw_hash.rb'
292-
293268
# Offense count: 3
294269
# This cop supports unsafe autocorrection (--autocorrect-all).
295270
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
@@ -315,12 +290,6 @@ Style/RedundantArgument:
315290
Exclude:
316291
- 'lib/puppet/provider/file_line/ruby.rb'
317292

318-
# Offense count: 1
319-
# This cop supports safe autocorrection (--autocorrect).
320-
Style/RedundantConstantBase:
321-
Exclude:
322-
- 'lib/puppet/functions/to_json_pretty.rb'
323-
324293
# Offense count: 1
325294
# This cop supports safe autocorrection (--autocorrect).
326295
Style/RedundantFileExtensionInRequire:

lib/facter/pe_version.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
confine is_pe: true
4444
setcode do
4545
pe_version = Facter.value(:pe_version)
46-
if pe_version
47-
pe_version.to_s.split('.')[0]
48-
end
46+
pe_version.to_s.split('.')[0] if pe_version
4947
end
5048
end
5149

@@ -54,9 +52,7 @@
5452
confine is_pe: true
5553
setcode do
5654
pe_version = Facter.value(:pe_version)
57-
if pe_version
58-
pe_version.to_s.split('.')[1]
59-
end
55+
pe_version.to_s.split('.')[1] if pe_version
6056
end
6157
end
6258

@@ -65,8 +61,6 @@
6561
confine is_pe: true
6662
setcode do
6763
pe_version = Facter.value(:pe_version)
68-
if pe_version
69-
pe_version.to_s.split('.')[2]
70-
end
64+
pe_version.to_s.split('.')[2] if pe_version
7165
end
7266
end

lib/puppet/functions/deprecation.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
def deprecation(key, message)
2222
if defined? Puppet::Pops::PuppetStack.stacktrace
23-
stacktrace = Puppet::Pops::PuppetStack.stacktrace()
23+
stacktrace = Puppet::Pops::PuppetStack.stacktrace
2424
file = stacktrace[0]
2525
line = stacktrace[1]
2626
message = "#{message} at #{file}:#{line}"
@@ -32,9 +32,7 @@ def deprecation(key, message)
3232
when :error
3333
raise("deprecation. #{key}. #{message}")
3434
else
35-
unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
36-
Puppet.deprecation_warning(message, key)
37-
end
35+
Puppet.deprecation_warning(message, key) unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
3836
end
3937
end
4038
end

lib/puppet/functions/stdlib/str2resource.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def str2resource(res_string)
2828

2929
resource = closure_scope.findresource(type_name, title)
3030

31-
if resource.nil?
32-
raise(Puppet::ParseError, "stdlib::str2resource(): could not find #{type_name}[#{title}], this is parse order dependent and values should not be quoted")
33-
end
31+
raise(Puppet::ParseError, "stdlib::str2resource(): could not find #{type_name}[#{title}], this is parse order dependent and values should not be quoted") if resource.nil?
3432

3533
resource
3634
end

lib/puppet/functions/to_json_pretty.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ def to_json_pretty(data, skip_undef = false, opts = nil)
6161
# It's not possible to make an abstract type that can be either a boolean
6262
# false or an integer, so we use -1 as the falsey value
6363
if opts
64-
opts = Hash[opts.map { |k, v| [k.to_sym, v] }]
64+
opts = opts.map { |k, v| [k.to_sym, v] }.to_h
6565

66-
if opts[:max_nesting] == -1
67-
opts[:max_nesting] = false
68-
end
66+
opts[:max_nesting] = false if opts[:max_nesting] == -1
6967
end
7068

7169
if skip_undef
@@ -77,6 +75,6 @@ def to_json_pretty(data, skip_undef = false, opts = nil)
7775
end
7876
# Call ::JSON to ensure it references the JSON library from Ruby's standard library
7977
# instead of a random JSON namespace that might be in scope due to user code.
80-
::JSON.pretty_generate(data, opts) << "\n"
78+
JSON.pretty_generate(data, opts) << "\n"
8179
end
8280
end

lib/puppet/parser/functions/any2array.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ module Puppet::Parser::Functions
3636
@return [Array] The new array containing the given object
3737
DOC
3838
) do |arguments|
39-
if arguments.empty?
40-
return []
41-
end
39+
return [] if arguments.empty?
4240

4341
return arguments unless arguments.length == 1
4442
return arguments[0] if arguments[0].is_a?(Array)

lib/puppet/parser/functions/any2bool.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,21 @@ module Puppet::Parser::Functions
2525
raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
2626

2727
# If argument is already Boolean, return it
28-
if !!arguments[0] == arguments[0] # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
29-
return arguments[0]
30-
end
28+
return arguments[0] if !!arguments[0] == arguments[0] # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
3129

3230
arg = arguments[0]
3331

34-
if arg.nil?
35-
return false
36-
end
32+
return false if arg.nil?
3733

38-
if arg == :undef
39-
return false
40-
end
34+
return false if arg == :undef
4135

4236
valid_float = begin
4337
!!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
4438
rescue
4539
false
4640
end
4741

48-
if arg.is_a?(Numeric)
49-
return function_num2bool([arguments[0]])
50-
end
42+
return function_num2bool([arguments[0]]) if arg.is_a?(Numeric)
5143

5244
if arg.is_a?(String)
5345
return function_num2bool([arguments[0]]) if valid_float

lib/puppet/parser/functions/base64.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ module Puppet::Parser::Functions
4141

4242
actions = ['encode', 'decode']
4343

44-
unless actions.include?(args[0])
45-
raise Puppet::ParseError, "base64(): the first argument must be one of 'encode' or 'decode'"
46-
end
44+
raise Puppet::ParseError, "base64(): the first argument must be one of 'encode' or 'decode'" unless actions.include?(args[0])
4745

48-
unless args[1].is_a?(String)
49-
raise Puppet::ParseError, 'base64(): the second argument must be a string to base64'
50-
end
46+
raise Puppet::ParseError, 'base64(): the second argument must be a string to base64' unless args[1].is_a?(String)
5147

5248
method = ['default', 'strict', 'urlsafe']
5349

@@ -57,9 +53,7 @@ module Puppet::Parser::Functions
5753
args[2]
5854
end
5955

60-
unless method.include?(chosen_method)
61-
raise Puppet::ParseError, "base64(): the third argument must be one of 'default', 'strict', or 'urlsafe'"
62-
end
56+
raise Puppet::ParseError, "base64(): the third argument must be one of 'default', 'strict', or 'urlsafe'" unless method.include?(chosen_method)
6357

6458
case args[0]
6559
when 'encode'

lib/puppet/parser/functions/bool2str.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,17 @@ module Puppet::Parser::Functions
3939
```
4040
DOC
4141
) do |arguments|
42-
unless arguments.size == 1 || arguments.size == 3
43-
raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)")
44-
end
42+
raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)") unless arguments.size == 1 || arguments.size == 3
4543

4644
value = arguments[0]
4745
true_string = arguments[1] || 'true'
4846
false_string = arguments[2] || 'false'
4947
klass = value.class
5048

5149
# We can have either true or false, and nothing else
52-
unless [FalseClass, TrueClass].include?(klass)
53-
raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with')
54-
end
50+
raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with') unless [FalseClass, TrueClass].include?(klass)
5551

56-
unless [true_string, false_string].all? { |x| x.is_a?(String) }
57-
raise(Puppet::ParseError, 'bool2str(): Requires strings to convert to')
58-
end
52+
raise(Puppet::ParseError, 'bool2str(): Requires strings to convert to') unless [true_string, false_string].all? { |x| x.is_a?(String) }
5953

6054
return value ? true_string : false_string
6155
end

lib/puppet/parser/functions/concat.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ module Puppet::Parser::Functions
3030
a = arguments[0]
3131

3232
# Check that the first parameter is an array
33-
unless a.is_a?(Array)
34-
raise(Puppet::ParseError, 'concat(): Requires array to work with')
35-
end
33+
raise(Puppet::ParseError, 'concat(): Requires array to work with') unless a.is_a?(Array)
3634

3735
result = a
3836
arguments.shift

lib/puppet/parser/functions/count.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ module Puppet::Parser::Functions
2727
@return [Integer] The amount of elements counted within the array
2828
DOC
2929
) do |args|
30-
if args.size > 2
31-
raise(ArgumentError, "count(): Wrong number of arguments given #{args.size} for 1 or 2.")
32-
end
30+
raise(ArgumentError, "count(): Wrong number of arguments given #{args.size} for 1 or 2.") if args.size > 2
3331

3432
collection, item = args
3533

lib/puppet/parser/functions/deep_merge.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ module Puppet::Parser::Functions
2424
@return [Hash] The merged hash
2525
DOC
2626

27-
if args.length < 2
28-
raise Puppet::ParseError, "deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)"
29-
end
27+
raise Puppet::ParseError, "deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)" if args.length < 2
3028

3129
deep_merge = proc do |hash1, hash2|
3230
hash1.merge(hash2) do |_key, old_value, new_value|
@@ -42,9 +40,7 @@ module Puppet::Parser::Functions
4240
args.each do |arg|
4341
next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef
4442
# If the argument was not a hash, skip it.
45-
unless arg.is_a?(Hash)
46-
raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments"
47-
end
43+
raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments" unless arg.is_a?(Hash)
4844

4945
result = deep_merge.call(result, arg)
5046
end

lib/puppet/parser/functions/defined_with_params.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
reference, params = vals
2828
raise(ArgumentError, 'Must specify a reference') unless reference
2929

30-
if !params || params == ''
31-
params = {}
32-
end
30+
params = {} if !params || params == ''
3331
ret = false
3432

3533
if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0

lib/puppet/parser/functions/delete_at.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,18 @@ module Puppet::Parser::Functions
3535

3636
array = arguments[0]
3737

38-
unless array.is_a?(Array)
39-
raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
40-
end
38+
raise(Puppet::ParseError, 'delete_at(): Requires array to work with') unless array.is_a?(Array)
4139

4240
index = arguments[1]
4341

44-
if index.is_a?(String) && !index.match(%r{^\d+$})
45-
raise(Puppet::ParseError, 'delete_at(): You must provide non-negative numeric index')
46-
end
42+
raise(Puppet::ParseError, 'delete_at(): You must provide non-negative numeric index') if index.is_a?(String) && !index.match(%r{^\d+$})
4743

4844
result = array.clone
4945

5046
# Numbers in Puppet are often string-encoded which is troublesome ...
5147
index = index.to_i
5248

53-
if index > result.size - 1 # First element is at index 0 is it not?
54-
raise(Puppet::ParseError, 'delete_at(): Given index exceeds size of array given')
55-
end
49+
raise(Puppet::ParseError, 'delete_at(): Given index exceeds size of array given') if index > result.size - 1 # First element is at index 0 is it not?
5650

5751
result.delete_at(index) # We ignore the element that got deleted ...
5852

0 commit comments

Comments
 (0)