Skip to content

Commit 5a851e9

Browse files
(PUP-11767) Fix HashTransformValues violations and remove from to_do
1 parent 99658eb commit 5a851e9

File tree

6 files changed

+8
-17
lines changed

6 files changed

+8
-17
lines changed

.rubocop_todo.yml

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

507-
# This cop supports unsafe auto-correction (--auto-correct-all).
508-
Style/HashTransformValues:
509-
Exclude:
510-
- 'lib/puppet/functions/group_by.rb'
511-
- 'lib/puppet/parser/scope.rb'
512-
- 'lib/puppet/pops/loader/task_instantiator.rb'
513-
- 'lib/puppet/pops/types/p_type_set_type.rb'
514-
- 'lib/puppet/transaction/report.rb'
515-
516507
# This cop supports safe auto-correction (--auto-correct).
517508
Style/IdenticalConditionalBranches:
518509
Exclude:

lib/puppet/functions/group_by.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def group_by_2a(array)
4949
yield(k, v)
5050
end
5151

52-
grouped.each_with_object({}) do |(k, v), hsh|
53-
hsh[k] = v.map { |item| item[1] }
52+
grouped.transform_values do |v|
53+
v.map { |item| item[1] }
5454
end.freeze
5555
end
5656

lib/puppet/parser/scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def as_read_only
260260
end
261261

262262
def to_hash
263-
@params.select { |_, access| access.assigned? }.to_h { |name, access| [name, access.value] }
263+
@params.select { |_, access| access.assigned? }.transform_values { |access| access.value }
264264
end
265265
end
266266

lib/puppet/pops/loader/task_instantiator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def self.create(loader, typed_name, source_refs)
3636
end
3737

3838
def self.convert_types(args)
39-
args.each_with_object({}) do |(k, v), hsh|
40-
hsh[k] = v['type'].nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(v['type'])
39+
args.transform_values do |v|
40+
v['type'].nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(v['type'])
4141
end if args
4242
end
4343
private_class_method :convert_types

lib/puppet/pops/types/p_type_set_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _pcore_init_hash
183183
result[KEY_NAME] = @name
184184
result[KEY_VERSION] = @version.to_s unless @version.nil?
185185
result[KEY_TYPES] = @types unless @types.empty?
186-
result[KEY_REFERENCES] = @references.to_h { |ref_alias, ref| [ref_alias, ref._pcore_init_hash] } unless @references.empty?
186+
result[KEY_REFERENCES] = @references.transform_values { |ref| ref._pcore_init_hash } unless @references.empty?
187187
result
188188
end
189189

lib/puppet/transaction/report.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def calculate_resource_statuses
328328
else
329329
@resource_statuses
330330
end
331-
resource_statuses.to_h { |key, rs| [key, rs.nil? ? nil : rs.to_data_hash] }
331+
resource_statuses.transform_values { |rs| rs.nil? ? nil : rs.to_data_hash }
332332
end
333333

334334
def to_data_hash
@@ -345,7 +345,7 @@ def to_data_hash
345345
'noop_pending' => @noop_pending,
346346
'environment' => @environment,
347347
'logs' => @logs.map { |log| log.to_data_hash },
348-
'metrics' => @metrics.to_h { |key, metric| [key, metric.to_data_hash] },
348+
'metrics' => @metrics.transform_values { |metric| metric.to_data_hash },
349349
'resource_statuses' => calculate_resource_statuses,
350350
'corrective_change' => @corrective_change,
351351
}

0 commit comments

Comments
 (0)