Skip to content

Commit 99ae2cf

Browse files
authored
Merge pull request #9231 from tvpartytonight/PUP-11767
(PUP-11767) Enable more style cops
2 parents a20a869 + 580d37d commit 99ae2cf

File tree

138 files changed

+273
-246
lines changed

Some content is hidden

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

138 files changed

+273
-246
lines changed

.rubocop.yml

+24
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,27 @@ Style/CaseEquality:
208208

209209
Style/CaseLikeIf:
210210
Enabled: true
211+
212+
Style/ClassCheck:
213+
Enabled: true
214+
215+
Style/ClassEqualityComparison:
216+
Enabled: true
217+
218+
Style/ClassMethods:
219+
Enabled: true
220+
221+
Style/CollectionCompact:
222+
Enabled: true
223+
224+
Style/ColonMethodCall:
225+
Enabled: true
226+
227+
Style/CombinableLoops:
228+
Enabled: true
229+
230+
Style/ColonMethodDefinition:
231+
Enabled: true
232+
233+
Style/DefWithParentheses:
234+
Enabled: true

.rubocop_todo.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ Style/CommentedKeyword:
341341
Style/ConditionalAssignment:
342342
Enabled: false
343343

344-
# This cop supports safe auto-correction (--auto-correct).
344+
# Enabling this would require reworking Puppet's use of DateTime's #rfc2822, #httptime, and _strptime
345+
Style/DateTime:
346+
Enabled: false
347+
345348
Style/DefWithParentheses:
346349
Enabled: false
347350

lib/puppet/application.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def app_defaults
372372
# Initialize application defaults. It's usually not necessary to override this method.
373373
# @return [void]
374374
# @api public
375-
def initialize_app_defaults()
375+
def initialize_app_defaults
376376
Puppet.settings.initialize_app_defaults(app_defaults)
377377
end
378378

lib/puppet/application/apply.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def apply_catalog(catalog)
366366

367367
# Returns facts or nil
368368
#
369-
def get_facts()
369+
def get_facts
370370
facts = nil
371371
unless Puppet[:node_name_fact].empty?
372372
# Collect our facts.
@@ -381,7 +381,7 @@ def get_facts()
381381

382382
# Returns the node or raises and error if node not found.
383383
#
384-
def get_node()
384+
def get_node
385385
node = Puppet::Node.indirection.find(Puppet[:node_name_value])
386386
raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node
387387

@@ -390,7 +390,7 @@ def get_node()
390390

391391
# Returns either a manifest (filename) or nil if apply should use content of Puppet[:code]
392392
#
393-
def get_manifest()
393+
def get_manifest
394394
manifest = nil
395395
# Set our code or file to use.
396396
if options[:code] or command_line.args.length == 0

lib/puppet/daemon.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def daemonize
5858

5959
# Close stdin/stdout/stderr so that we can finish our transition into 'daemon' mode.
6060
# @return nil
61-
def self.close_streams()
61+
def self.close_streams
6262
Puppet.debug("Closing streams for daemon mode")
6363
begin
6464
$stdin.reopen "/dev/null"
@@ -68,15 +68,15 @@ def self.close_streams()
6868
Puppet.debug("Finished closing streams for daemon mode")
6969
rescue => detail
7070
Puppet.err "Could not start #{Puppet.run_mode.name}: #{detail}"
71-
Puppet::Util::replace_file("/tmp/daemonout", 0644) do |f|
71+
Puppet::Util.replace_file("/tmp/daemonout", 0644) do |f|
7272
f.puts "Could not start #{Puppet.run_mode.name}: #{detail}"
7373
end
7474
exit(12)
7575
end
7676
end
7777

7878
# Convenience signature for calling Puppet::Daemon.close_streams
79-
def close_streams()
79+
def close_streams
8080
Puppet::Daemon.close_streams
8181
end
8282

lib/puppet/face/generate.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
raise ArgumentError, _("The output directory '%{outputdir}' exists and is not a directory") % { outputdir: outputdir }
5959
end
6060

61-
Puppet::FileSystem::mkpath(outputdir)
61+
Puppet::FileSystem.mkpath(outputdir)
6262

6363
generator.generate(inputs, outputdir, options[:force])
6464

lib/puppet/face/help.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def legacy_applications
160160
# @return [Array] An Array of Arrays. The outer array contains one entry per application; each
161161
# element in the outer array is a pair whose first element is a String containing the application
162162
# name, and whose second element is a String containing the summary for that application.
163-
def all_application_summaries()
163+
def all_application_summaries
164164
available_application_names_special_sort().inject([]) do |result, appname|
165165
next result if exclude_from_docs?(appname)
166166

@@ -196,7 +196,7 @@ def all_application_summaries()
196196
COMMON = 'Common:'
197197
SPECIALIZED = 'Specialized:'
198198
BLANK = "\n"
199-
def available_application_names_special_sort()
199+
def available_application_names_special_sort
200200
full_list = Puppet::Application.available_application_names
201201
a_list = full_list & %w{apply agent config help lookup module resource}
202202
a_list = a_list.sort

lib/puppet/file_bucket/file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def checksum_data(base_method)
125125
end
126126

127127
def to_binary
128-
Puppet::FileSystem::binread(@path)
128+
Puppet::FileSystem.binread(@path)
129129
end
130130
end
131131
end

lib/puppet/file_system/windows.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def chmod(mode, path)
115115

116116
def read_preserve_line_endings(path)
117117
contents = path.read(:mode => 'rb', :encoding => 'bom|utf-8')
118-
contents = path.read(:mode => 'rb', :encoding => "bom|#{Encoding::default_external.name}") unless contents.valid_encoding?
118+
contents = path.read(:mode => 'rb', :encoding => "bom|#{Encoding.default_external.name}") unless contents.valid_encoding?
119119
contents = path.read unless contents.valid_encoding?
120120

121121
contents

lib/puppet/functions/break.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
dispatch :break_impl do
3838
end
3939

40-
def break_impl()
40+
def break_impl
4141
# get file, line if available, else they are set to nil
4242
file, line = Puppet::Pops::PuppetStack.top_of_stack
4343

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def self.get_puppet_type(property)
6161
enum = strings.empty? ? nil : "Enum[#{strings.join(', ')}]"
6262
pattern = regexes.empty? ? nil : "Pattern[#{regexes.join(', ')}]"
6363
boolean = strings.include?('\'true\'') || strings.include?('\'false\'') ? 'Boolean' : nil
64-
variant = [boolean, enum, pattern].reject { |t| t.nil? }
64+
variant = [boolean, enum, pattern].compact
6565
return variant[0] if variant.size == 1
6666

6767
"Variant[#{variant.join(', ')}]"

lib/puppet/generate/type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def format=(format)
4949
# @return [Boolean] Returns true if the output is up-to-date or false if not.
5050
def up_to_date?(outputdir)
5151
f = effective_output_path(outputdir)
52-
Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
52+
Puppet::FileSystem.exist?(f) && (Puppet::FileSystem.stat(@path) <=> Puppet::FileSystem.stat(f)) <= 0
5353
end
5454

5555
# Gets the filename of the output file.

lib/puppet/indirector/json.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def path(name, ext = '.json')
5050

5151
private
5252

53-
def data_dir()
53+
def data_dir
5454
Puppet.run_mode.server? ? Puppet[:server_datadir] : Puppet[:client_datadir]
5555
end
5656

lib/puppet/module_tool.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def self.username_and_modname_from(full_module_name)
4848
# @return [Pathname, nil] the root path of the module directory or nil if
4949
# we cannot find one
5050
def self.find_module_root(path)
51-
path = Pathname.new(path) if path.class == String
51+
path = Pathname.new(path) if path.instance_of?(String)
5252

5353
path.expand_path.ascend do |p|
5454
return p if is_module_root?(p)
@@ -63,7 +63,7 @@ def self.find_module_root(path)
6363
# @param path [Pathname, String] path to analyse
6464
# @return [Boolean] true if the path is a module root, false otherwise
6565
def self.is_module_root?(path)
66-
path = Pathname.new(path) if path.class == String
66+
path = Pathname.new(path) if path.instance_of?(String)
6767

6868
FileTest.file?(path + 'metadata.json')
6969
end

lib/puppet/node/environment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def hash
552552
end
553553

554554
# not private so it can be called in tests
555-
def self.extralibs()
555+
def self.extralibs
556556
if ENV['PUPPETLIB']
557557
split_path(ENV['PUPPETLIB'])
558558
else

lib/puppet/pal/compiler.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def initialize(internal_compiler)
2525
#
2626
def call_function(function_name, *args, &block)
2727
# TRANSLATORS: do not translate variable name strings in these assertions
28-
Pal::assert_non_empty_string(function_name, 'function_name', false)
29-
Pal::assert_type(Pal::T_ANY_ARRAY, args, 'args', false)
28+
Pal.assert_non_empty_string(function_name, 'function_name', false)
29+
Pal.assert_type(Pal::T_ANY_ARRAY, args, 'args', false)
3030
internal_evaluator.evaluator.external_call_function(function_name, args, topscope, &block)
3131
end
3232

lib/puppet/parser/ast/hostclass.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def instantiate(modname)
2323
return all_types
2424
end
2525

26-
def code()
26+
def code
2727
@context[:code]
2828
end
2929
end

lib/puppet/parser/ast/pops_bridge.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def instantiate_NodeDefinition(o, modname)
227227
end
228228
end
229229

230-
def code()
230+
def code
231231
Expression.new(:value => @value)
232232
end
233233

lib/puppet/parser/ast/resource.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def evaluate(scope)
6161
resource
6262
end
6363
end
64-
end.flatten.reject { |resource| resource.nil? }
64+
end.flatten.compact
6565
end
6666
end

lib/puppet/parser/compiler.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def validate_catalog(validation_stage)
164164
end
165165

166166
# Constructs the overrides for the context
167-
def context_overrides()
167+
def context_overrides
168168
{
169169
:current_environment => environment,
170170
:global_scope => @topscope, # 4x placeholder for new global scope
@@ -240,7 +240,7 @@ def evaluate_classes(classes, scope, lazy_evaluate = true)
240240
class_parameters = nil
241241
# if we are a param class, save the classes hash
242242
# and transform classes to be the keys
243-
if classes.class == Hash
243+
if classes.instance_of?(Hash)
244244
class_parameters = classes
245245
classes = classes.keys
246246
end
@@ -543,7 +543,7 @@ def initvars
543543
@resources = []
544544

545545
# Make sure any external node classes are in our class list
546-
if @node.classes.class == Hash
546+
if @node.classes.instance_of?(Hash)
547547
@catalog.add_class(*@node.classes.keys)
548548
else
549549
@catalog.add_class(*@node.classes)

lib/puppet/parser/functions/assert_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:assert_type,
55
:type => :rvalue,
66
:arity => -3,

lib/puppet/parser/functions/binary_file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:binary_file,
55
:type => :rvalue,
66
:arity => 1,

lib/puppet/parser/functions/break.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:break,
55
:arity => 0,
66
:doc => <<~DOC

lib/puppet/parser/functions/contain.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Called within a class definition, establishes a containment
44
# relationship with another class
55

6-
Puppet::Parser::Functions::newfunction(
6+
Puppet::Parser::Functions.newfunction(
77
:contain,
88
:arity => -2,
99
:doc => "Contain one or more classes inside the current class. If any of

lib/puppet/parser/functions/create_resources.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(:create_resources, :arity => -3, :doc => <<-'ENDHEREDOC') do |args|
3+
Puppet::Parser::Functions.newfunction(:create_resources, :arity => -3, :doc => <<-'ENDHEREDOC') do |args|
44
Converts a hash into a set of resources and adds them to the catalog.
55
66
**Note**: Use this function selectively. It's generally better to write resources in

lib/puppet/parser/functions/defined.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:defined,
55
:type => :rvalue,
66
:arity => -2,

lib/puppet/parser/functions/dig.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:dig,
55
:type => :rvalue,
66
:arity => -1,

lib/puppet/parser/functions/digest.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative '../../../puppet/util/checksums'
4-
Puppet::Parser::Functions::newfunction(:digest, :type => :rvalue, :arity => 1, :doc => "Returns a hash value from a provided string using the digest_algorithm setting from the Puppet config file.") do |args|
4+
Puppet::Parser::Functions.newfunction(:digest, :type => :rvalue, :arity => 1, :doc => "Returns a hash value from a provided string using the digest_algorithm setting from the Puppet config file.") do |args|
55
algo = Puppet[:digest_algorithm]
66
Puppet::Util::Checksums.method(algo.intern).call args[0]
77
end

lib/puppet/parser/functions/each.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:each,
55
:type => :rvalue,
66
:arity => -3,

lib/puppet/parser/functions/epp.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(:epp, :type => :rvalue, :arity => -2, :doc =>
3+
Puppet::Parser::Functions.newfunction(:epp, :type => :rvalue, :arity => -2, :doc =>
44
"Evaluates an Embedded Puppet (EPP) template file and returns the rendered text
55
result as a String.
66

lib/puppet/parser/functions/fail.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:fail,
55
:arity => -1,
66
:doc => <<~DOC

lib/puppet/parser/functions/file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require_relative '../../../puppet/file_system'
44

5-
Puppet::Parser::Functions::newfunction(
5+
Puppet::Parser::Functions.newfunction(
66
:file, :arity => -2, :type => :rvalue,
77
:doc => "Loads a file from a module and returns its contents as a string.
88

lib/puppet/parser/functions/filter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:filter,
55
:type => :rvalue,
66
:arity => -3,

lib/puppet/parser/functions/find_file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Parser::Functions::newfunction(
3+
Puppet::Parser::Functions.newfunction(
44
:find_file,
55
:type => :rvalue,
66
:arity => -2,

lib/puppet/parser/functions/fqdn_rand.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'digest/md5'
44
require 'digest/sha2'
55

6-
Puppet::Parser::Functions::newfunction(:fqdn_rand, :arity => -2, :type => :rvalue, :doc =>
6+
Puppet::Parser::Functions.newfunction(:fqdn_rand, :arity => -2, :type => :rvalue, :doc =>
77
"Usage: `fqdn_rand(MAX, [SEED], [DOWNCASE])`. MAX is required and must be a positive
88
integer; SEED is optional and may be any number or string; DOWNCASE is optional
99
and should be a boolean true or false.

0 commit comments

Comments
 (0)