Skip to content

Commit 1d90cde

Browse files
(PUP-11767) Enable Style/MapToHash
1 parent 753fb9c commit 1d90cde

File tree

16 files changed

+34
-33
lines changed

16 files changed

+34
-33
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,6 @@ Style/LineEndConcatenation:
349349

350350
Style/MapCompactWithConditionalBlock:
351351
Enabled: true
352+
353+
Style/MapToHash:
354+
Enabled: true

lib/puppet/context/trusted_information.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def self.remote(authenticated, node_name, certificate)
5454
if certificate.nil?
5555
Puppet.info(_('TrustedInformation expected a certificate, but none was given.'))
5656
else
57-
extensions = certificate.custom_extensions.collect do |ext|
57+
extensions = certificate.custom_extensions.to_h do |ext|
5858
[ext['oid'].freeze, ext['value'].freeze]
59-
end.to_h
59+
end
6060
end
6161
new('remote', node_name, extensions, external)
6262
else

lib/puppet/face/parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
unless errors.empty?
8787
ignore_error_keys = [:arguments, :environment, :node]
8888

89-
data = errors.map do |file, error|
89+
data = errors.to_h do |file, error|
9090
file_errors = error.to_h.reject { |k, _| ignore_error_keys.include?(k) }
9191
[file, file_errors]
92-
end.to_h
92+
end
9393

9494
puts Puppet::Util::Json.dump(Puppet::Pops::Serialization::ToDataConverter.convert(data, rich_data: false, symbol_as_string: true), :pretty => true)
9595

lib/puppet/generate/models/type/type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def initialize(type)
4040
Property.new(type.paramclass(name))
4141
end
4242
sc = Puppet::Pops::Types::StringConverter.singleton
43-
@title_patterns = type.title_patterns.map do |mapping|
43+
@title_patterns = type.title_patterns.to_h do |mapping|
4444
[
4545
sc.convert(mapping[0], '%p'),
4646
sc.convert(mapping[1].map do |names|
@@ -50,7 +50,7 @@ def initialize(type)
5050
names[0].to_s
5151
end, '%p')
5252
]
53-
end.to_h
53+
end
5454
@isomorphic = type.isomorphic?
5555
# continue to emit capability as false when rendering the ERB
5656
# template, so that pcore modules generated prior to puppet7 can be

lib/puppet/network/http/api/server/v3/environments.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def initialize(env_loader)
1313
@env_loader = env_loader
1414
end
1515

16-
# rubocop:disable Layout/MultilineMethodCallIndentation
1716
def call(request, response)
1817
response
1918
.respond_with(
@@ -22,7 +21,7 @@ def call(request, response)
2221
Puppet::Util::Json
2322
.dump({
2423
"search_paths" => @env_loader.search_paths,
25-
"environments" => @env_loader.list.collect do |env|
24+
"environments" => @env_loader.list.to_h do |env|
2625
[env.name, {
2726
"settings" => {
2827
"modulepath" => env.full_modulepath,
@@ -31,11 +30,10 @@ def call(request, response)
3130
"config_version" => env.config_version || '',
3231
}
3332
}]
34-
end.to_h
33+
end
3534
})
3635
)
3736
end
38-
# rubocop:enable Layout/MultilineMethodCallIndentation
3937

4038
private
4139

lib/puppet/node/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def modules
379379

380380
# @api private
381381
def modules_by_name
382-
@modules_by_name ||= modules.map { |mod| [mod.name, mod] }.to_h
382+
@modules_by_name ||= modules.to_h { |mod| [mod.name, mod] }
383383
end
384384
private :modules_by_name
385385

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? }.map { |name, access| [name, access.value] }.to_h
263+
@params.select { |_, access| access.assigned? }.to_h { |name, access| [name, access.value] }
264264
end
265265
end
266266

lib/puppet/pops/types/p_meta_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def resolve_hash(loader, init_hash)
6969
def resolve_type_refs(loader, o)
7070
case o
7171
when Hash
72-
o.map { |k, v| [resolve_type_refs(loader, k), resolve_type_refs(loader, v)] }.to_h
72+
o.to_h { |k, v| [resolve_type_refs(loader, k), resolve_type_refs(loader, v)] }
7373
when Array
7474
o.map { |e| resolve_type_refs(loader, e) }
7575
when PAnyType

lib/puppet/pops/types/p_object_type.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -755,27 +755,27 @@ def _pcore_init_from_hash(init_hash)
755755
end
756756

757757
unless attr_specs.empty?
758-
@attributes = attr_specs.map do |key, attr_spec|
758+
@attributes = attr_specs.to_h do |key, attr_spec|
759759
unless attr_spec.is_a?(Hash)
760760
attr_type = TypeAsserter.assert_instance_of(nil, PTypeType::DEFAULT, attr_spec) { "attribute #{label}[#{key}]" }
761761
attr_spec = { KEY_TYPE => attr_type }
762762
attr_spec[KEY_VALUE] = nil if attr_type.is_a?(POptionalType)
763763
end
764764
attr = PAttribute.new(key, self, attr_spec)
765765
[attr.name, attr.assert_override(parent_members)]
766-
end.to_h.freeze
766+
end.freeze
767767
end
768768

769769
func_specs = init_hash[KEY_FUNCTIONS]
770770
unless func_specs.nil? || func_specs.empty?
771-
@functions = func_specs.map do |key, func_spec|
771+
@functions = func_specs.to_h do |key, func_spec|
772772
func_spec = { KEY_TYPE => TypeAsserter.assert_instance_of(nil, TYPE_FUNCTION_TYPE, func_spec) { "function #{label}[#{key}]" } } unless func_spec.is_a?(Hash)
773773
func = PFunction.new(key, self, func_spec)
774774
name = func.name
775775
raise Puppet::ParseError, _("%{label} conflicts with attribute with the same name") % { label: func.label } if @attributes.include?(name)
776776

777777
[name, func.assert_override(parent_members)]
778-
end.to_h.freeze
778+
end.freeze
779779
end
780780

781781
@equality_include_type = init_hash[KEY_EQUALITY_INCLUDE_TYPE]
@@ -1081,7 +1081,7 @@ def collect_equality_attributes(collector)
10811081
# All attributes except constants participate
10821082
collector.merge!(@attributes.reject { |_, attr| attr.kind == ATTRIBUTE_KIND_CONSTANT })
10831083
else
1084-
collector.merge!(@equality.map { |attr_name| [attr_name, @attributes[attr_name]] }.to_h)
1084+
collector.merge!(@equality.to_h { |attr_name| [attr_name, @attributes[attr_name]] })
10851085
end
10861086
nil
10871087
end
@@ -1098,14 +1098,14 @@ def collect_type_parameters(collector, include_parent)
10981098
private
10991099

11001100
def compressed_members_hash(features)
1101-
features.values.map do |feature|
1101+
features.values.to_h do |feature|
11021102
fh = feature._pcore_init_hash
11031103
if fh.size == 1
11041104
type = fh[KEY_TYPE]
11051105
fh = type unless type.nil?
11061106
end
11071107
[feature.name, fh]
1108-
end.to_h
1108+
end
11091109
end
11101110

11111111
# @return [PObjectType] the topmost parent who's #equality_attributes include the given _attr_

lib/puppet/pops/types/p_type_set_type.rb

Lines changed: 3 additions & 3 deletions
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.map { |ref_alias, ref| [ref_alias, ref._pcore_init_hash] }.to_h unless @references.empty?
186+
result[KEY_REFERENCES] = @references.to_h { |ref_alias, ref| [ref_alias, ref._pcore_init_hash] } unless @references.empty?
187187
result
188188
end
189189

@@ -328,11 +328,11 @@ def resolve_literal_hash(loader, init_hash_expression)
328328

329329
# @api private
330330
def resolve_hash(loader, init_hash)
331-
result = init_hash.map do |key, value|
331+
result = init_hash.to_h do |key, value|
332332
key = resolve_type_refs(loader, key)
333333
value = resolve_type_refs(loader, value) unless key == KEY_TYPES && value.is_a?(Hash)
334334
[key, value]
335-
end.to_h
335+
end
336336
name_auth = resolve_name_authority(result, loader)
337337
types = result[KEY_TYPES]
338338
if types.is_a?(Hash)

0 commit comments

Comments
 (0)