Skip to content

Commit 4e3c155

Browse files
authored
Merge pull request #9235 from tvpartytonight/PUP-11767_working
(PUP-11767) enable remaining style cops
2 parents f9bcd09 + 4461351 commit 4e3c155

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+288
-272
lines changed

.rubocop.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,87 @@ Style/ExpandPathArguments:
271271

272272
Style/FetchEnvVar:
273273
Enabled: true
274+
275+
Style/FileRead:
276+
Enabled: true
277+
278+
Style/FileWrite:
279+
Enabled: true
280+
281+
Style/FloatDivision:
282+
Enabled: true
283+
284+
Style/For:
285+
Enabled: true
286+
287+
Style/FrozenStringLiteralComment:
288+
Enabled: true
289+
290+
Style/GlobalStdStream:
291+
Enabled: true
292+
293+
Style/GlobalVars:
294+
Enabled: true
295+
296+
Style/HashAsLastArrayItem:
297+
Enabled: true
298+
299+
Style/HashConversion:
300+
Enabled: true
301+
302+
# HashEachMethods does not guarantee the receiver is a Hash, so
303+
# this will not work since numerous puppet classes define #value
304+
# not #each_value
305+
Style/HashEachMethods:
306+
Enabled: false
307+
308+
Style/HashLikeCase:
309+
Enabled: true
310+
311+
Style/HashTransformKeys:
312+
Enabled: true
313+
314+
Style/HashTransformValues:
315+
Enabled: true
316+
317+
Style/IdenticalConditionalBranches:
318+
Enabled: true
319+
320+
Style/IfInsideElse:
321+
Enabled: true
322+
323+
Style/IfUnlessModifierOfIfUnless:
324+
Enabled: true
325+
326+
Style/IfWithBooleanLiteralBranches:
327+
Enabled: true
328+
329+
Style/IfWithSemicolon:
330+
Enabled: true
331+
332+
Style/InfiniteLoop:
333+
Enabled: true
334+
335+
Style/InverseMethods:
336+
Enabled: true
337+
338+
Style/KeywordParametersOrder:
339+
Enabled: true
340+
341+
Style/Lambda:
342+
Enabled: true
343+
344+
Style/LambdaCall:
345+
Enabled: true
346+
347+
Style/LineEndConcatenation:
348+
Enabled: true
349+
350+
Style/MapCompactWithConditionalBlock:
351+
Enabled: true
352+
353+
Style/MapToHash:
354+
Enabled: true
355+
356+
Style/MapToSet:
357+
Enabled: true

.rubocop_todo.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ Style/IfWithSemicolon:
640640
Exclude:
641641
- 'lib/puppet/pops/parser/evaluating_parser.rb'
642642

643+
# This cop requires significant changes to testing, will require its own effort
644+
Style/ImplicitRuntimeError:
645+
Enabled: false
646+
643647
# This cop supports unsafe auto-correction (--auto-correct-all).
644648
Style/InfiniteLoop:
645649
Exclude:

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.to_h do |ext|
5858
[ext['oid'].freeze, ext['value'].freeze]
59-
end]
59+
end
6060
end
6161
new('remote', node_name, extensions, external)
6262
else

lib/puppet/defaults.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def self.initialize_default_settings!(settings)
489489
},
490490
:daemonize => {
491491
:type => :boolean,
492-
:default => (Puppet::Util::Platform.windows? ? false : true),
492+
:default => (!Puppet::Util::Platform.windows?),
493493
:desc => "Whether to send the process into the background. This defaults
494494
to true on POSIX systems, and to false on Windows (where Puppet
495495
currently cannot daemonize).",

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/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/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.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]
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/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

0 commit comments

Comments
 (0)