Skip to content

Commit 4856544

Browse files
committed
Layout/CaseIndentation
This commit enables the Rubocop Layout/CaseIndentation cop.
1 parent bde140e commit 4856544

34 files changed

+429
-441
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ Layout/AssignmentIndentation:
6969
- 'lib/puppet/util.rb'
7070
- 'lib/puppet/util/windows/daemon.rb'
7171

72-
# This cop supports safe auto-correction (--auto-correct).
73-
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
74-
# SupportedStyles: case, end
75-
Layout/CaseIndentation:
76-
Enabled: false
77-
7872
# This cop supports safe auto-correction (--auto-correct).
7973
Layout/ClosingHeredocIndentation:
8074
Enabled: false

lib/puppet/file_system/uniquefile.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def path
100100

101101
def make_tmpname(prefix_suffix, n)
102102
case prefix_suffix
103-
when String
104-
prefix = prefix_suffix
105-
suffix = ""
106-
when Array
107-
prefix = prefix_suffix[0]
108-
suffix = prefix_suffix[1]
109-
else
110-
raise ArgumentError, _("unexpected prefix_suffix: %{value}") % { value: prefix_suffix.inspect }
103+
when String
104+
prefix = prefix_suffix
105+
suffix = ""
106+
when Array
107+
prefix = prefix_suffix[0]
108+
suffix = prefix_suffix[1]
109+
else
110+
raise ArgumentError, _("unexpected prefix_suffix: %{value}") % { value: prefix_suffix.inspect }
111111
end
112112
t = Time.now.strftime("%Y%m%d")
113113
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"

lib/puppet/http/dns.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def each_srv_record(domain, service_name = :puppet, &block)
4949
Puppet.debug "Searching for SRV records for domain: #{domain}"
5050

5151
case service_name
52-
when :puppet then service = '_x-puppet'
53-
when :file then service = '_x-puppet-fileserver'
54-
else service = "_x-puppet-#{service_name}"
52+
when :puppet then service = '_x-puppet'
53+
when :file then service = '_x-puppet-fileserver'
54+
else service = "_x-puppet-#{service_name}"
5555
end
5656
record_name = "#{service}._tcp.#{domain}"
5757

lib/puppet/indirector/catalog/compiler.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ def get_content_uri(metadata, source, environment_path)
158158
# Also used to profile/log reasons for not inlining.
159159
def inlineable?(resource, sources)
160160
case
161-
when resource[:ensure] == 'absent'
162-
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
163-
return Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false }
164-
when sources.empty?
165-
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
166-
return Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false }
167-
when (not (sources.all? {|source| source =~ /^puppet:/}))
168-
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
169-
return Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false }
170-
else
171-
return true
161+
when resource[:ensure] == 'absent'
162+
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
163+
return Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false }
164+
when sources.empty?
165+
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
166+
return Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false }
167+
when (not (sources.all? {|source| source =~ /^puppet:/}))
168+
#TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining)
169+
return Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false }
170+
else
171+
return true
172172
end
173173
end
174174

lib/puppet/module_tool/metadata.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ def validate_name(name)
172172
modname = :namespace_missing if namespace == ''
173173

174174
err = case modname
175-
when nil, '', :namespace_missing
176-
_("the field must be a namespaced module name")
177-
when /[^a-z0-9_]/i
178-
_("the module name contains non-alphanumeric (or underscore) characters")
179-
when /^[^a-z]/i
180-
_("the module name must begin with a letter")
181-
else
182-
_("the namespace contains non-alphanumeric characters")
175+
when nil, '', :namespace_missing
176+
_("the field must be a namespaced module name")
177+
when /[^a-z0-9_]/i
178+
_("the module name contains non-alphanumeric (or underscore) characters")
179+
when /^[^a-z]/i
180+
_("the module name must begin with a letter")
181+
else
182+
_("the namespace contains non-alphanumeric characters")
183183
end
184184

185185
raise ArgumentError, _("Invalid 'name' field in metadata.json: %{err}") % { err: err }

lib/puppet/pops/evaluator/access_operator.rb

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,36 @@ def access_Binary(o, scope, keys)
4343
def access_String(o, scope, keys)
4444
keys.flatten!
4545
result = case keys.size
46-
when 0
47-
fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size})
48-
when 1
49-
# Note that Ruby 1.8.7 requires a length of 1 to produce a String
50-
k1 = Utils.to_n(keys[0])
51-
bad_string_access_key_type(o, 0, k1.nil? ? keys[0] : k1) unless k1.is_a?(Integer)
52-
k2 = 1
53-
k1 = k1 < 0 ? o.length + k1 : k1 # abs pos
54-
# if k1 is outside, a length of 1 always produces an empty string
55-
if k1 < 0
56-
EMPTY_STRING
57-
else
58-
o[ k1, k2 ]
59-
end
60-
when 2
61-
k1 = Utils.to_n(keys[0])
62-
k2 = Utils.to_n(keys[1])
63-
[k1, k2].each_with_index { |k,i| bad_string_access_key_type(o, i, k.nil? ? keys[i] : k) unless k.is_a?(Integer) }
64-
65-
k1 = k1 < 0 ? o.length + k1 : k1 # abs pos (negative is count from end)
66-
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
67-
# if k1 is outside, adjust to first position, and adjust length
68-
if k1 < 0
69-
k2 = k2 + k1
70-
k1 = 0
71-
end
72-
o[ k1, k2 ]
73-
else
74-
fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size})
75-
end
46+
when 0
47+
fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size})
48+
when 1
49+
# Note that Ruby 1.8.7 requires a length of 1 to produce a String
50+
k1 = Utils.to_n(keys[0])
51+
bad_string_access_key_type(o, 0, k1.nil? ? keys[0] : k1) unless k1.is_a?(Integer)
52+
k2 = 1
53+
k1 = k1 < 0 ? o.length + k1 : k1 # abs pos
54+
# if k1 is outside, a length of 1 always produces an empty string
55+
if k1 < 0
56+
EMPTY_STRING
57+
else
58+
o[ k1, k2 ]
59+
end
60+
when 2
61+
k1 = Utils.to_n(keys[0])
62+
k2 = Utils.to_n(keys[1])
63+
[k1, k2].each_with_index { |k,i| bad_string_access_key_type(o, i, k.nil? ? keys[i] : k) unless k.is_a?(Integer) }
64+
65+
k1 = k1 < 0 ? o.length + k1 : k1 # abs pos (negative is count from end)
66+
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
67+
# if k1 is outside, adjust to first position, and adjust length
68+
if k1 < 0
69+
k2 = k2 + k1
70+
k1 = 0
71+
end
72+
o[ k1, k2 ]
73+
else
74+
fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size})
75+
end
7676
# Specified as: an index outside of range, or empty result == empty string
7777
(result.nil? || result.empty?) ? EMPTY_STRING : result
7878
end
@@ -592,15 +592,15 @@ def access_PResourceType(o, scope, keys)
592592
# type_name is LHS type_name if set, else the first given arg
593593
type_name = o.type_name || Types::TypeFormatter.singleton.capitalize_segments(keys.shift)
594594
type_name = case type_name
595-
when Types::PResourceType
596-
type_name.type_name
597-
when String
598-
type_name
599-
else
600-
# blame given left expression if it defined the type, else the first given key expression
601-
blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr
602-
fail(Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)})
603-
end
595+
when Types::PResourceType
596+
type_name.type_name
597+
when String
598+
type_name
599+
else
600+
# blame given left expression if it defined the type, else the first given key expression
601+
blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr
602+
fail(Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)})
603+
end
604604

605605
# type name must conform
606606
if type_name !~ Patterns::CLASSREF_EXT

lib/puppet/pops/evaluator/evaluator_impl.rb

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,31 +1208,30 @@ def concatenate(x, y)
12081208
case x
12091209
when Array
12101210
y = case y
1211-
when Array then y
1212-
when Hash then y.to_a
1213-
else
1214-
[y]
1215-
end
1211+
when Array then y
1212+
when Hash then y.to_a
1213+
else [y]
1214+
end
12161215
x + y # new array with concatenation
12171216
when Hash
12181217
y = case y
1219-
when Hash then y
1220-
when Array
1221-
# Hash[[a, 1, b, 2]] => {}
1222-
# Hash[a,1,b,2] => {a => 1, b => 2}
1223-
# Hash[[a,1], [b,2]] => {[a,1] => [b,2]}
1224-
# Hash[[[a,1], [b,2]]] => {a => 1, b => 2}
1225-
# Use type calculator to determine if array is Array[Array[?]], and if so use second form
1226-
# of call
1227-
t = @@type_calculator.infer(y)
1228-
if t.element_type.is_a? Types::PArrayType
1229-
Hash[y]
1230-
else
1231-
Hash[*y]
1232-
end
1233-
else
1234-
raise ArgumentError.new(_('Can only append Array or Hash to a Hash'))
1235-
end
1218+
when Hash then y
1219+
when Array
1220+
# Hash[[a, 1, b, 2]] => {}
1221+
# Hash[a,1,b,2] => {a => 1, b => 2}
1222+
# Hash[[a,1], [b,2]] => {[a,1] => [b,2]}
1223+
# Hash[[[a,1], [b,2]]] => {a => 1, b => 2}
1224+
# Use type calculator to determine if array is Array[Array[?]], and if so use second form
1225+
# of call
1226+
t = @@type_calculator.infer(y)
1227+
if t.element_type.is_a? Types::PArrayType
1228+
Hash[y]
1229+
else
1230+
Hash[*y]
1231+
end
1232+
else
1233+
raise ArgumentError.new(_('Can only append Array or Hash to a Hash'))
1234+
end
12361235
x.merge y # new hash with overwrite
12371236
when URI
12381237
raise ArgumentError.new(_('An URI can only be merged with an URI or String')) unless y.is_a?(String) || y.is_a?(URI)
@@ -1256,16 +1255,16 @@ def delete(x, y)
12561255
case x
12571256
when Array
12581257
y = case y
1259-
when Array then y
1260-
when Hash then y.to_a
1258+
when Array then y
1259+
when Hash then y.to_a
12611260
else
12621261
[y]
12631262
end
12641263
y.each {|e| result.delete(e) }
12651264
when Hash
12661265
y = case y
1267-
when Array then y
1268-
when Hash then y.keys
1266+
when Array then y
1267+
when Hash then y.keys
12691268
else
12701269
[y]
12711270
end

lib/puppet/pops/evaluator/runtime3_converter.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,23 @@ def convert_PCatalogEntryType(o, scope, undef_value)
133133
def catalog_type_to_split_type_title(catalog_type)
134134
split_type = catalog_type.is_a?(Puppet::Pops::Types::PTypeType) ? catalog_type.type : catalog_type
135135
case split_type
136-
when Puppet::Pops::Types::PClassType
137-
class_name = split_type.class_name
138-
['class', class_name.nil? ? nil : class_name.sub(/^::/, '')]
139-
when Puppet::Pops::Types::PResourceType
140-
type_name = split_type.type_name
141-
title = split_type.title
142-
if type_name =~ /^(::)?[Cc]lass$/
143-
['class', title.nil? ? nil : title.sub(/^::/, '')]
144-
else
145-
# Ensure that title is '' if nil
146-
# Resources with absolute name always results in error because tagging does not support leading ::
147-
[type_name.nil? ? nil : type_name.sub(/^::/, '').downcase, title.nil? ? '' : title]
148-
end
136+
when Puppet::Pops::Types::PClassType
137+
class_name = split_type.class_name
138+
['class', class_name.nil? ? nil : class_name.sub(/^::/, '')]
139+
when Puppet::Pops::Types::PResourceType
140+
type_name = split_type.type_name
141+
title = split_type.title
142+
if type_name =~ /^(::)?[Cc]lass$/
143+
['class', title.nil? ? nil : title.sub(/^::/, '')]
149144
else
150-
#TRANSLATORS 'PClassType' and 'PResourceType' are Puppet types and should not be translated
151-
raise ArgumentError, _("Cannot split the type %{class_name}, it represents neither a PClassType, nor a PResourceType.") %
152-
{ class_name: catalog_type.class }
145+
# Ensure that title is '' if nil
146+
# Resources with absolute name always results in error because tagging does not support leading ::
147+
[type_name.nil? ? nil : type_name.sub(/^::/, '').downcase, title.nil? ? '' : title]
148+
end
149+
else
150+
#TRANSLATORS 'PClassType' and 'PResourceType' are Puppet types and should not be translated
151+
raise ArgumentError, _("Cannot split the type %{class_name}, it represents neither a PClassType, nor a PResourceType.") %
152+
{ class_name: catalog_type.class }
153153
end
154154
end
155155

lib/puppet/pops/lookup/explainer.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -469,32 +469,32 @@ def initialize(explain_options = false, only_explain_options = false)
469469

470470
def push(qualifier_type, qualifier)
471471
node = case (qualifier_type)
472-
when :global
473-
ExplainGlobal.new(@current, qualifier)
474-
when :location
475-
ExplainLocation.new(@current, qualifier)
476-
when :interpolate
477-
ExplainInterpolate.new(@current, qualifier)
478-
when :data_provider
479-
ExplainDataProvider.new(@current, qualifier)
480-
when :merge
481-
ExplainMerge.new(@current, qualifier)
482-
when :module
483-
ExplainModule.new(@current, qualifier)
484-
when :scope
485-
ExplainScope.new(@current, qualifier)
486-
when :sub_lookup
487-
ExplainSubLookup.new(@current, qualifier)
488-
when :segment
489-
ExplainKeySegment.new(@current, qualifier)
490-
when :meta, :data
491-
ExplainTop.new(@current, qualifier_type, qualifier)
492-
when :invalid_key
493-
ExplainInvalidKey.new(@current, qualifier)
494-
else
495-
#TRANSLATORS 'Explain' is referring to the 'Explainer' class and should not be translated
496-
raise ArgumentError, _("Unknown Explain type %{qualifier_type}") % { qualifier_type: qualifier_type }
497-
end
472+
when :global
473+
ExplainGlobal.new(@current, qualifier)
474+
when :location
475+
ExplainLocation.new(@current, qualifier)
476+
when :interpolate
477+
ExplainInterpolate.new(@current, qualifier)
478+
when :data_provider
479+
ExplainDataProvider.new(@current, qualifier)
480+
when :merge
481+
ExplainMerge.new(@current, qualifier)
482+
when :module
483+
ExplainModule.new(@current, qualifier)
484+
when :scope
485+
ExplainScope.new(@current, qualifier)
486+
when :sub_lookup
487+
ExplainSubLookup.new(@current, qualifier)
488+
when :segment
489+
ExplainKeySegment.new(@current, qualifier)
490+
when :meta, :data
491+
ExplainTop.new(@current, qualifier_type, qualifier)
492+
when :invalid_key
493+
ExplainInvalidKey.new(@current, qualifier)
494+
else
495+
#TRANSLATORS 'Explain' is referring to the 'Explainer' class and should not be translated
496+
raise ArgumentError, _("Unknown Explain type %{qualifier_type}") % { qualifier_type: qualifier_type }
497+
end
498498
@current.branches << node
499499
@current = node
500500
end

0 commit comments

Comments
 (0)