Skip to content

Commit 883dbcf

Browse files
(PUP-11767) Enable Style/IfInsideElse
1 parent a7a86df commit 883dbcf

31 files changed

+147
-206
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,6 @@ Style/HashTransformValues:
316316

317317
Style/IdenticalConditionalBranches:
318318
Enabled: true
319+
320+
Style/IfInsideElse:
321+
Enabled: true

lib/puppet/face/help.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@
5050
if options.has_key? :version
5151
if options[:version].to_s !~ /^current$/i
5252
version = options[:version]
53-
else
54-
if args.length == 0
55-
# TRANSLATORS '--version' is a command line option and should not be translated
56-
raise ArgumentError, _("Supplying a '--version' only makes sense when a Faces subcommand is given")
57-
end
53+
elsif args.length == 0
54+
raise ArgumentError, _("Supplying a '--version' only makes sense when a Faces subcommand is given")
55+
# TRANSLATORS '--version' is a command line option and should not be translated
5856
end
5957
end
6058

@@ -66,18 +64,16 @@
6664

6765
# legacy apps already emit ronn output
6866
return render_application_help(facename)
67+
elsif options[:ronn]
68+
render_face_man(facename || :help)
69+
# Calling `puppet help <app> --ronn` normally calls this action with
70+
# <app> as the first argument in the `args` array. However, if <app>
71+
# happens to match the name of an action, like `puppet help help
72+
# --ronn`, then face_base "eats" the argument and `args` will be
73+
# empty. Rather than force users to type `puppet help help help
74+
# --ronn`, default the facename to `:help`
6975
else
70-
if options[:ronn]
71-
# Calling `puppet help <app> --ronn` normally calls this action with
72-
# <app> as the first argument in the `args` array. However, if <app>
73-
# happens to match the name of an action, like `puppet help help
74-
# --ronn`, then face_base "eats" the argument and `args` will be
75-
# empty. Rather than force users to type `puppet help help help
76-
# --ronn`, default the facename to `:help`
77-
render_face_man(facename || :help)
78-
else
79-
render_face_help(facename, actionname, version)
80-
end
76+
render_face_help(facename, actionname, version)
8177
end
8278
end
8379
end

lib/puppet/http/service.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ def add_puppet_headers(headers)
107107
Puppet[:http_extra_headers].each do |name, value|
108108
if modified_headers.keys.find { |key| key.casecmp(name) == 0 }
109109
Puppet.warning(_('Ignoring extra header "%{name}" as it was previously set.') % { name: name })
110+
elsif value.nil? || value.empty?
111+
Puppet.warning(_('Ignoring extra header "%{name}" as it has no value.') % { name: name })
110112
else
111-
if value.nil? || value.empty?
112-
Puppet.warning(_('Ignoring extra header "%{name}" as it has no value.') % { name: name })
113-
else
114-
modified_headers[name] = value
115-
end
113+
modified_headers[name] = value
116114
end
117115
end
118116
modified_headers

lib/puppet/indirector/catalog/compiler.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,13 @@ def compile(node, options)
323323
benchmark_str = _("Compiled static catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
324324
profile_str = _("Compiled static catalog for %{node}") % { node: node.name }
325325
end
326+
elsif node.environment
327+
escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
328+
benchmark_str = _("Compiled catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
329+
profile_str = _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
326330
else
327-
if node.environment
328-
escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
329-
benchmark_str = _("Compiled catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
330-
profile_str = _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
331-
else
332-
benchmark_str = _("Compiled catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
333-
profile_str = _("Compiled catalog for %{node}") % { node: node.name }
334-
end
331+
benchmark_str = _("Compiled catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
332+
profile_str = _("Compiled catalog for %{node}") % { node: node.name }
335333
end
336334
config = nil
337335

lib/puppet/pal/pal_impl.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ def self.with_script_compiler(
7979

8080
# Use the manifest setting
8181
manifest_file = Puppet[:manifest]
82-
else
82+
elsif manifest_file.nil? && code_string.nil?
8383
# An "undef" code_string is the only way to override Puppet[:manifest] & Puppet[:code] settings since an
8484
# empty string is taken as Puppet[:code] not being set.
8585
#
86-
if manifest_file.nil? && code_string.nil?
87-
code_string = 'undef'
88-
end
86+
code_string = 'undef'
8987
end
9088

9189
previous_tasks_value = Puppet[:tasks]
@@ -186,13 +184,11 @@ def self.with_catalog_compiler(
186184

187185
# Use the manifest setting
188186
manifest_file = Puppet[:manifest]
189-
else
187+
elsif manifest_file.nil? && code_string.nil?
190188
# An "undef" code_string is the only way to override Puppet[:manifest] & Puppet[:code] settings since an
191189
# empty string is taken as Puppet[:code] not being set.
192190
#
193-
if manifest_file.nil? && code_string.nil?
194-
code_string = 'undef'
195-
end
191+
code_string = 'undef'
196192
end
197193

198194
# We need to make sure to set these back when we're done

lib/puppet/parameter/value_collection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def newvalue(name, options = {}, &block)
154154
devfail "Cannot use :call value ':none' in combination with a block for property '#{self.class.name}'" if call_opt == :none
155155
value.block = block
156156
value.method ||= "set_#{value.name}" if !value.regex?
157-
else
158-
devfail "Cannot use :call value ':instead' without a block for property '#{self.class.name}'" if call_opt == :instead
157+
elsif call_opt == :instead
158+
devfail "Cannot use :call value ':instead' without a block for property '#{self.class.name}'"
159159
end
160160
value
161161
end

lib/puppet/parser/resource.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@ def override_parameter(param)
305305
_("Parameter '%{name}' is already set on %{resource} at %{error_location}; cannot redefine") %
306306
{ name: param.name, resource: ref, error_location: error_location_str }
307307
end
308+
elsif error_location_str.empty?
309+
_("Parameter '%{name}' is already set on %{resource} by %{source}; cannot redefine") %
310+
{ name: param.name, resource: ref, source: current.source.to_s }
308311
else
309-
if error_location_str.empty?
310-
_("Parameter '%{name}' is already set on %{resource} by %{source}; cannot redefine") %
311-
{ name: param.name, resource: ref, source: current.source.to_s }
312-
else
313-
_("Parameter '%{name}' is already set on %{resource} by %{source} at %{error_location}; cannot redefine") %
314-
{ name: param.name, resource: ref, source: current.source.to_s, error_location: error_location_str }
315-
end
312+
_("Parameter '%{name}' is already set on %{resource} by %{source} at %{error_location}; cannot redefine") %
313+
{ name: param.name, resource: ref, source: current.source.to_s, error_location: error_location_str }
316314
end
317315
raise Puppet::ParseError.new(msg, param.file, param.line)
318316
end

lib/puppet/pops/evaluator/access_operator.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,10 @@ def access_PObjectType(o, scope, keys)
349349
keys.flatten!
350350
if o.resolved? && !o.name.nil?
351351
Types::PObjectTypeExtension.create(o, keys)
352+
elsif keys.size == 1
353+
Types::TypeFactory.object(keys[0])
352354
else
353-
if keys.size == 1
354-
Types::TypeFactory.object(keys[0])
355-
else
356-
fail(Issues::BAD_TYPE_SLICE_ARITY, @semantic, { :base_type => 'Object-Type', :min => 1, :actual => keys.size })
357-
end
355+
fail(Issues::BAD_TYPE_SLICE_ARITY, @semantic, { :base_type => 'Object-Type', :min => 1, :actual => keys.size })
358356
end
359357
end
360358

lib/puppet/pops/evaluator/closure.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,12 @@ def combine_values_with_parameters(scope, args)
253253
# correct non array default value
254254
value = [value]
255255
end
256-
else
256+
elsif param_captures
257257
# not given, does not have default
258-
if param_captures
259-
# default for captures rest is an empty array
260-
value = []
261-
else
262-
@evaluator.fail(Issues::MISSING_REQUIRED_PARAMETER, parameter, { :param_name => parameter.name })
263-
end
258+
value = []
259+
# default for captures rest is an empty array
260+
else
261+
@evaluator.fail(Issues::MISSING_REQUIRED_PARAMETER, parameter, { :param_name => parameter.name })
264262
end
265263
else
266264
given_argument = args[index]

lib/puppet/pops/functions/dispatch.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ def weave(scope, args)
9090
else
9191
raise ArgumentError, _("Unknown injection %{injection_name}") % { injection_name: injection_name }
9292
end
93-
else
93+
elsif knit < 0
9494
# Careful so no new nil arguments are added since they would override default
9595
# parameter values in the received
96-
if knit < 0
97-
idx = -knit - 1
98-
new_args += args[idx..] if idx < args.size
99-
else
100-
new_args << args[knit] if knit < args.size
101-
end
96+
idx = -knit - 1
97+
new_args += args[idx..] if idx < args.size
98+
elsif knit < args.size
99+
new_args << args[knit]
102100
end
103101
end
104102
new_args

0 commit comments

Comments
 (0)