Skip to content

Commit d288d40

Browse files
(PUP-11767) Fix IdenticalConditionalBranches violations and remove from to_do
1 parent 5a851e9 commit d288d40

File tree

9 files changed

+14
-39
lines changed

9 files changed

+14
-39
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,6 @@ Style/GuardClause:
504504
Style/HashSyntax:
505505
Enabled: false
506506

507-
# This cop supports safe auto-correction (--auto-correct).
508-
Style/IdenticalConditionalBranches:
509-
Exclude:
510-
- 'lib/puppet/functions/filter.rb'
511-
- 'lib/puppet/network/http_pool.rb'
512-
- 'lib/puppet/node.rb'
513-
- 'lib/puppet/parser/resource.rb'
514-
- 'lib/puppet/pops/loader/module_loaders.rb'
515-
- 'lib/puppet/pops/types/p_type_set_type.rb'
516-
- 'lib/puppet/type.rb'
517-
- 'lib/puppet/util/feature.rb'
518-
519507
# This cop supports safe auto-correction (--auto-correct).
520508
# Configuration parameters: AllowIfModifier.
521509
Style/IfInsideElse:

lib/puppet/functions/filter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def filter_Enumerable_2(enumerable)
124124
if enum.hash_style?
125125
result = {}
126126
enum.each { |k, v| result[k] = v if yield(k, v) }
127-
result
128127
else
129128
result = []
130129
begin
@@ -133,7 +132,7 @@ def filter_Enumerable_2(enumerable)
133132
end
134133
rescue StopIteration
135134
end
136-
result
137135
end
136+
result
138137
end
139138
end

lib/puppet/network/http_pool.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ def self.http_instance(host, port, use_ssl = true, verify_peer = true)
3636

3737
if verify_peer
3838
verifier = Puppet::SSL::Verifier.new(host, nil)
39-
http_client_class.new(host, port, use_ssl: use_ssl, verifier: verifier)
4039
else
4140
ssl = Puppet::SSL::SSLProvider.new
4241
verifier = Puppet::SSL::Verifier.new(host, ssl.create_insecure_context)
43-
http_client_class.new(host, port, use_ssl: use_ssl, verifier: verifier)
4442
end
43+
http_client_class.new(host, port, use_ssl: use_ssl, verifier: verifier)
4544
end
4645

4746
# Retrieve a connection for the given host and port.

lib/puppet/node.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def serializable_parameters
6060
end
6161

6262
def environment
63-
if @environment
64-
@environment
65-
else
63+
unless @environment
6664
env = parameters[ENVIRONMENT]
6765
if env
6866
self.environment = env
@@ -76,8 +74,8 @@ def environment
7674
self.environment = Puppet.lookup(:environments).get!(Puppet[:environment])
7775
end
7876

79-
@environment
8077
end
78+
@environment
8179
end
8280

8381
def environment=(env)

lib/puppet/parser/resource.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def evaluate
9090
def exported=(value)
9191
if value
9292
@virtual = true
93-
@exported = value
9493
else
95-
@exported = value
9694
end
95+
@exported = value
9796
end
9897

9998
# Finish the evaluation by assigning defaults and scope tags
@@ -226,10 +225,9 @@ def to_hash
226225
if value.is_a?(Array)
227226
value = value.flatten.reject { |v| v.nil? || :undef == v }
228227
end
229-
result[param.name] = value
230228
else
231-
result[param.name] = value
232229
end
230+
result[param.name] = value
233231
end
234232
end)
235233
end

lib/puppet/pops/loader/module_loaders.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,10 @@ def find_existing_path(typed_name)
410410
# related to origin
411411
if origin.is_a?(Array)
412412
origins = origin.filter_map { |ori| existing_path(ori) }
413-
return [origins, sp] unless origins.empty?
414413
else
415414
origins = candidate_paths(origin)
416-
return [origins, sp] unless origins.empty?
417415
end
416+
return [origins, sp] unless origins.empty?
418417
else
419418
existing = existing_path(origin)
420419
return [origin, sp] unless existing.nil?

lib/puppet/pops/types/p_type_set_type.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,13 @@ def defines_type?(t)
238238
def name_for(t, default_name)
239239
key = @types.key(t)
240240
if key.nil?
241-
if @references.empty?
242-
default_name
243-
else
241+
unless @references.empty?
244242
@references.each_pair do |ref_key, ref|
245243
ref_name = ref.type_set.name_for(t, nil)
246244
return "#{ref_key}::#{ref_name}" unless ref_name.nil?
247245
end
248-
default_name
249246
end
247+
default_name
250248
else
251249
key
252250
end

lib/puppet/type.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,7 @@ def managed?
955955
# Once an object is managed, it always stays managed; but an object
956956
# that is listed as unmanaged might become managed later in the process,
957957
# so we have to check that every time
958-
if @managed
959-
return @managed
960-
else
958+
unless @managed
961959
@managed = false
962960
properties.each { |property|
963961
s = property.should
@@ -966,8 +964,8 @@ def managed?
966964
break
967965
end
968966
}
969-
return @managed
970967
end
968+
return @managed
971969
end
972970

973971
###############################

lib/puppet/util/feature.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ def add(name, options = {}, &block)
5252
# * the result was true/false
5353
# OR
5454
# * we're configured to never retry
55-
if @results.has_key?(name) &&
56-
(!@results[name].nil? || !Puppet[:always_retry_plugins])
57-
!!@results[name]
58-
else
55+
unless @results.has_key?(name) &&
56+
(!@results[name].nil? || !Puppet[:always_retry_plugins])
5957
@results[name] = test(name, options, &block)
60-
!!@results[name]
6158
end
59+
!!@results[name]
6260
end
6361
end
6462

0 commit comments

Comments
 (0)