Skip to content

Commit 35c9550

Browse files
committed
Lint/ShadowedArgument
Lookup.lookup called 'reduce' but it didn't read or modify the 'memo' passed into the block. It was using 'reduce' as a way to return the first found match, either returned by 'search_and_merge' or contained in 'default_values'. I think the code more clearly shows what's going on now. FileSetting#validate is dead code, remove it. PortSetting#munge now explicitly passes `value` to super so it's clear the value is read before overwritten.
1 parent fb61eca commit 35c9550

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,6 @@ Lint/RescueException:
661661
- 'lib/puppet/util/command_line/trollop.rb'
662662
- 'util/rspec_grouper'
663663

664-
# Configuration parameters: IgnoreImplicitReferences.
665-
Lint/ShadowedArgument:
666-
Exclude:
667-
- 'lib/puppet/pops/lookup.rb'
668-
- 'lib/puppet/settings/file_setting.rb'
669-
- 'lib/puppet/settings/port_setting.rb'
670-
671664
Lint/StructNewOverride:
672665
Exclude:
673666
- 'lib/puppet/network/http/request.rb'

lib/puppet/pops/lookup.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,26 @@ def self.lookup(name, value_type, default_value, has_default, merge, lookup_invo
2727
# with name and value.
2828
not_found = MergeStrategy::NOT_FOUND
2929
override_values = lookup_invocation.override_values
30-
result_with_name = names.reduce([nil, not_found]) do |memo, key|
30+
result_with_name = [nil, not_found]
31+
names.each do |key|
3132
value = override_values.include?(key) ? assert_type(["Value found for key '%s' in override hash", key], value_type, override_values[key]) : not_found
3233
catch(:no_such_key) { value = search_and_merge(key, lookup_invocation, merge, false) } if value.equal?(not_found)
33-
break [key, assert_type('Found value', value_type, value)] unless value.equal?(not_found)
34-
memo
34+
next if value.equal?(not_found)
35+
36+
result_with_name = [key, assert_type('Found value', value_type, value)]
37+
break
3538
end
3639

3740
# Use the 'default_values' hash as a last resort if nothing is found
3841
if result_with_name[1].equal?(not_found)
3942
default_values = lookup_invocation.default_values
4043
unless default_values.empty?
41-
result_with_name = names.reduce(result_with_name) do |memo, key|
44+
names.each do |key|
4245
value = default_values.include?(key) ? assert_type(["Value found for key '%s' in default values hash", key], value_type, default_values[key]) : not_found
43-
memo = [key, value]
44-
break memo unless value.equal?(not_found)
45-
memo
46+
next if value.equal?(not_found)
47+
48+
result_with_name = [key, value]
49+
break
4650
end
4751
end
4852
end

lib/puppet/settings/file_setting.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,6 @@ def to_resource
169169
resource
170170
end
171171

172-
# Make sure any provided variables look up to something.
173-
def validate(value)
174-
return true unless value.is_a? String
175-
value.scan(/\$(\w+)/) { |name|
176-
name = $1
177-
unless @settings.include?(name)
178-
raise ArgumentError,
179-
_("Settings parameter '%{name}' is undefined") % { name: name }
180-
end
181-
}
182-
end
183-
184172
# @api private
185173
# @param option [String] Extra file operation mode information to use
186174
# (defaults to read-only mode 'r')

lib/puppet/settings/port_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
class Puppet::Settings::PortSetting < Puppet::Settings::IntegerSetting
33
def munge(value)
4-
value = super
4+
value = super(value)
55

66
if value < 0 || value > 65535
77
raise Puppet::Settings::ValidationError, _("Value '%{value}' is not a valid port number for parameter: %{name}") % { value: value.inspect, name: @name }

0 commit comments

Comments
 (0)