Skip to content

Commit 61101ce

Browse files
(PUP-11767) Fix EmptyCaseCondition and remove from rubocop_todo
1 parent 4465db3 commit 61101ce

File tree

7 files changed

+34
-51
lines changed

7 files changed

+34
-51
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,6 @@ Style/DoubleNegation:
422422
- 'lib/puppet/util/feature.rb'
423423
- 'lib/puppet/util/windows/adsi.rb'
424424

425-
# This cop supports safe auto-correction (--auto-correct).
426-
Style/EmptyCaseCondition:
427-
Exclude:
428-
- 'lib/puppet/pops/serialization/serializer.rb'
429-
- 'lib/puppet/pops/types/type_calculator.rb'
430-
- 'lib/puppet/settings.rb'
431-
- 'lib/puppet/settings/duration_setting.rb'
432-
- 'lib/puppet/settings/priority_setting.rb'
433-
- 'lib/puppet/settings/ttl_setting.rb'
434-
- 'lib/puppet/type.rb'
435-
436425
# This cop supports safe auto-correction (--auto-correct).
437426
# Configuration parameters: EnforcedStyle.
438427
# SupportedStyles: empty, nil, both

lib/puppet/pops/serialization/serializer.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,31 @@ def inspect
105105
# @param [Object] value the value to write
106106
# @api private
107107
def write_tabulated_first_time(value)
108-
case
109-
when value.instance_of?(Symbol),
110-
value.instance_of?(Regexp),
111-
value.instance_of?(SemanticPuppet::Version),
112-
value.instance_of?(SemanticPuppet::VersionRange),
113-
value.instance_of?(Time::Timestamp),
114-
value.instance_of?(Time::Timespan),
115-
value.instance_of?(Types::PBinaryType::Binary),
116-
value.is_a?(URI)
108+
if value.instance_of?(Symbol) ||
109+
value.instance_of?(Regexp) ||
110+
value.instance_of?(SemanticPuppet::Version) ||
111+
value.instance_of?(SemanticPuppet::VersionRange) ||
112+
value.instance_of?(Time::Timestamp) ||
113+
value.instance_of?(Time::Timespan) ||
114+
value.instance_of?(Types::PBinaryType::Binary) ||
115+
value.is_a?(URI)
117116
push_written(value)
118117
@writer.write(value)
119-
when value.instance_of?(Array)
118+
elsif value.instance_of?(Array)
120119
push_written(value)
121120
start_array(value.size)
122121
value.each { |elem| write(elem) }
123-
when value.instance_of?(Hash)
122+
elsif value.instance_of?(Hash)
124123
push_written(value)
125124
start_map(value.size)
126125
value.each_pair { |key, val| write(key); write(val) }
127-
when value.instance_of?(Types::PSensitiveType::Sensitive)
126+
elsif value.instance_of?(Types::PSensitiveType::Sensitive)
128127
start_sensitive
129128
write(value.unwrap)
130-
when value.instance_of?(Types::PTypeReferenceType)
129+
elsif value.instance_of?(Types::PTypeReferenceType)
131130
push_written(value)
132131
@writer.write(value)
133-
when value.is_a?(Types::PuppetObject)
132+
elsif value.is_a?(Types::PuppetObject)
134133
value._pcore_type.write(value, self)
135134
else
136135
impl_class = value.class

lib/puppet/pops/types/type_calculator.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,26 @@ def type(c)
214214
raise ArgumentError, 'Argument must be a Module' unless c.is_a? Module
215215

216216
# Can't use a visitor here since we don't have an instance of the class
217-
case
218-
when c <= Integer
217+
if c <= Integer
219218
type = PIntegerType::DEFAULT
220-
when c == Float
219+
elsif c == Float
221220
type = PFloatType::DEFAULT
222-
when c == Numeric
221+
elsif c == Numeric
223222
type = PNumericType::DEFAULT
224-
when c == String
223+
elsif c == String
225224
type = PStringType::DEFAULT
226-
when c == Regexp
225+
elsif c == Regexp
227226
type = PRegexpType::DEFAULT
228-
when c == NilClass
227+
elsif c == NilClass
229228
type = PUndefType::DEFAULT
230-
when c == FalseClass, c == TrueClass
229+
elsif c == FalseClass || c == TrueClass
231230
type = PBooleanType::DEFAULT
232-
when c == Class
231+
elsif c == Class
233232
type = PTypeType::DEFAULT
234-
when c == Array
233+
elsif c == Array
235234
# Assume array of any
236235
type = PArrayType::DEFAULT
237-
when c == Hash
236+
elsif c == Hash
238237
# Assume hash of any
239238
type = PHashType::DEFAULT
240239
else

lib/puppet/settings.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,15 +1306,14 @@ def issue_deprecation_warning(setting, msg = nil)
13061306
name = setting.name
13071307
ref = DEPRECATION_REFS.find { |params, _reference| params.include?(name) }
13081308
ref = ref[1] if ref
1309-
case
1310-
when msg
1309+
if msg
13111310
msg << " #{ref}" if ref
13121311
Puppet.deprecation_warning(msg)
1313-
when setting.completely_deprecated?
1312+
elsif setting.completely_deprecated?
13141313
message = _("Setting %{name} is deprecated.") % { name: name }
13151314
message += " #{ref}"
13161315
Puppet.deprecation_warning(message, "setting-#{name}")
1317-
when setting.allowed_on_commandline?
1316+
elsif setting.allowed_on_commandline?
13181317
# TRANSLATORS 'puppet.conf' is a file name and should not be translated
13191318
message = _("Setting %{name} is deprecated in puppet.conf.") % { name: name }
13201319
message += " #{ref}"

lib/puppet/settings/duration_setting.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ def type
2222

2323
# Convert the value to an integer, parsing numeric string with units if necessary.
2424
def munge(value)
25-
case
26-
when value.is_a?(Integer) || value.nil?
25+
if value.is_a?(Integer) || value.nil?
2726
value
28-
when (value.is_a?(String) and value =~ FORMAT)
27+
elsif (value.is_a?(String) and value =~ FORMAT)
2928
$1.to_i * UNITMAP[$2 || 's']
3029
else
3130
raise Puppet::Settings::ValidationError, _("Invalid duration format '%{value}' for parameter: %{name}") % { value: value.inspect, name: @name }

lib/puppet/settings/priority_setting.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ def type
3131
def munge(value)
3232
return unless value
3333

34-
case
35-
when value.is_a?(Integer)
34+
if value.is_a?(Integer)
3635
value
37-
when (value.is_a?(String) and value =~ /\d+/)
36+
elsif (value.is_a?(String) and value =~ /\d+/)
3837
value.to_i
39-
when (value.is_a?(String) and PRIORITY_MAP[value.to_sym])
38+
elsif (value.is_a?(String) and PRIORITY_MAP[value.to_sym])
4039
PRIORITY_MAP[value.to_sym]
4140
else
4241
raise Puppet::Settings::ValidationError, _("Invalid priority format '%{value}' for parameter: %{name}") % { value: value.inspect, name: @name }

lib/puppet/settings/ttl_setting.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ def print(value)
3434

3535
# Convert the value to Numeric, parsing numeric string with units if necessary.
3636
def self.munge(value, param_name)
37-
case
38-
when value.is_a?(Numeric)
37+
if value.is_a?(Numeric)
3938
if value < 0
4039
raise Puppet::Settings::ValidationError, _("Invalid negative 'time to live' %{value} - did you mean 'unlimited'?") % { value: value.inspect }
4140
end
4241

4342
value
4443

45-
when value == 'unlimited'
44+
elsif value == 'unlimited'
4645
Float::INFINITY
4746

48-
when (value.is_a?(String) and value =~ FORMAT)
47+
elsif (value.is_a?(String) and value =~ FORMAT)
4948
$1.to_i * UNITMAP[$2 || 's']
5049
else
5150
raise Puppet::Settings::ValidationError, _("Invalid 'time to live' format '%{value}' for parameter: %{param_name}") % { value: value.inspect, param_name: param_name }

0 commit comments

Comments
 (0)