Skip to content

Commit d035114

Browse files
(PUP-11767) Enable Style/HashConversion
1 parent 9c1ef63 commit d035114

File tree

30 files changed

+54
-50
lines changed

30 files changed

+54
-50
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,6 @@ Style/GlobalVars:
295295

296296
Style/HashAsLastArrayItem:
297297
Enabled: true
298+
299+
Style/HashConversion:
300+
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 = Hash[certificate.custom_extensions.collect do |ext|
57+
extensions = certificate.custom_extensions.collect do |ext|
5858
[ext['oid'].freeze, ext['value'].freeze]
59-
end]
59+
end.to_h
6060
end
6161
new('remote', node_name, extensions, external)
6262
else

lib/puppet/forge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def initialize(source, data)
146146
dependencies = []
147147
end
148148

149-
super(source, name, version, Hash[dependencies])
149+
super(source, name, version, dependencies.to_h)
150150
end
151151

152152
def install(dir)

lib/puppet/functions/filter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@
9696
def filter_Hash_1(hash)
9797
result = hash.select { |x, y| yield([x, y]) }
9898
# Ruby 1.8.7 returns Array
99-
result = Hash[result] unless result.is_a? Hash
99+
result = result.to_h unless result.is_a? Hash
100100
result
101101
end
102102

103103
def filter_Hash_2(hash)
104104
result = hash.select { |x, y| yield(x, y) }
105105
# Ruby 1.8.7 returns Array
106-
result = Hash[result] unless result.is_a? Hash
106+
result = result.to_h unless result.is_a? Hash
107107
result
108108
end
109109

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 = Hash[type.title_patterns.map do |mapping|
43+
@title_patterns = type.title_patterns.map 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]
53+
end.to_h
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/module_tool/local_tarball.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def initialize(source, mod)
5656
dependencies = mod.dependencies.map do |dep|
5757
Puppet::ModuleTool.parse_module_dependency(release, dep)[0..1]
5858
end
59-
dependencies = Hash[dependencies]
59+
dependencies = dependencies.to_h
6060
end
6161

6262
super(source, name, version, dependencies || {})

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

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

16+
# rubocop:disable Layout/MultilineMethodCallIndentation
1617
def call(request, response)
1718
response
1819
.respond_with(
@@ -21,7 +22,7 @@ def call(request, response)
2122
Puppet::Util::Json
2223
.dump({
2324
"search_paths" => @env_loader.search_paths,
24-
"environments" => Hash[@env_loader.list.collect do |env|
25+
"environments" => @env_loader.list.collect do |env|
2526
[env.name, {
2627
"settings" => {
2728
"modulepath" => env.full_modulepath,
@@ -30,10 +31,11 @@ def call(request, response)
3031
"config_version" => env.config_version || '',
3132
}
3233
}]
33-
end]
34+
end.to_h
3435
})
3536
)
3637
end
38+
# rubocop:enable Layout/MultilineMethodCallIndentation
3739

3840
private
3941

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 ||= Hash[modules.map { |mod| [mod.name, mod] }]
382+
@modules_by_name ||= modules.map { |mod| [mod.name, mod] }.to_h
383383
end
384384
private :modules_by_name
385385

lib/puppet/parser/compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def evaluate_node_classes
191191
# The results from Hash#partition are arrays of pairs rather than hashes,
192192
# so we have to convert to the forms evaluate_classes expects (Hash, and
193193
# Array of class names)
194-
classes_with_params = Hash[classes_with_params]
194+
classes_with_params = classes_with_params.to_h
195195
classes_without_params.map!(&:first)
196196
else
197197
classes_with_params = {}

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

0 commit comments

Comments
 (0)