Skip to content

Commit

Permalink
Layout/EmptyLineAfterGuardClause
Browse files Browse the repository at this point in the history
This commit enables the Rubocop Layout/EmptyLineAfterGuardClause cop.
  • Loading branch information
mhashizume committed Dec 18, 2023
1 parent 775592c commit e44831f
Show file tree
Hide file tree
Showing 325 changed files with 875 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ AllCops:
- 'lib/puppet/vendor/**/*'
- 'lib/puppet/pops/parser/eparser.rb'

Layout/EmptyLineAfterGuardClause:
Enabled: true

# puppet uses symbol booleans in types and providers to work around long standing
# bugs when trying to manage falsey pararameters and properties
Lint/BooleanSymbol:
Expand Down
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ Layout/DotPosition:
Layout/ElseAlignment:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterMagicComment:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/agent/disabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def disable_message
if data.has_key?(DISABLED_MESSAGE_JSON_KEY)
return data[DISABLED_MESSAGE_JSON_KEY]
end

nil
end

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def clear?
# Thus, long-running background processes can potentially finish their work before a restart.
def controlled_run(&block)
return unless clear?

result = block.call
Process.kill(:HUP, $PID) if restart_requested?
result
Expand Down Expand Up @@ -304,6 +305,7 @@ def run_mode(mode_name = nil)
# @api public
def environment_mode(mode_name)
raise Puppet::Error, _("Invalid environment mode '%{mode_name}'") % { mode_name: mode_name } unless [:local, :remote, :not_required].include?(mode_name)

@environment_mode = mode_name
end

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def log_config

Puppet.settings.stringify_settings(:agent, :all).each_pair do |k,v|
next if k.include?("password") || v.to_s.empty?

Puppet.debug("Using setting: #{k}=#{v}")
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/application/apply.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def get_facts()
def get_node()
node = Puppet::Node.indirection.find(Puppet[:node_name_value])
raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node

node
end

Expand All @@ -395,6 +396,7 @@ def get_manifest()
else
manifest = command_line.args.shift
raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)

Puppet.warning(_("Only one file can be applied per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
end
manifest
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/application/describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(width)

def wrap(txt, opts)
return "" unless txt && !txt.empty?

work = (opts[:scrub] ? scrub(txt) : txt)
indent = (opts[:indent] ? opts[:indent] : 0)
textLen = @width - indent
Expand Down Expand Up @@ -59,6 +60,7 @@ def initialize
Puppet::Type.loadall
Puppet::Type.eachtype { |type|
next if type.name == :component

@types[type.name] = type
}
end
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def main
if options[:facts] and !options[:target]
raise _("facts command requires target")
end

unless options[:apply].nil?
raise _("missing argument: --target is required when using --apply") if options[:target].nil?
raise _("%{file} does not exist, cannot apply") % { file: options[:apply] } unless File.file?(options[:apply])
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/application/face_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def find_global_settings_argument(item)
Puppet.settings.each do |_name, object|
object.optparse_args.each do |arg|
next unless arg =~ /^-/

# sadly, we have to emulate some of optparse here...
pattern = /^#{arg.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/
pattern.match item and return object
Expand All @@ -170,8 +171,10 @@ def find_application_argument(item)
self.class.option_parser_commands.each do |options, _function|
options.each do |option|
next unless option =~ /^-/

pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/
next unless pattern.match(item)

return {
:argument => option =~ /[ =]/,
:optional => option =~ /[ =]\[/
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/application/filebucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def run_command
@args = command_line.args
command = args.shift
return send(command) if %w{get backup restore diff list}.include? command

help
end

Expand Down Expand Up @@ -255,6 +256,7 @@ def restore

def diff
raise Puppet::Error, _("Need exactly two arguments: filebucket diff <file_a> <file_b>") unless args.count == 2

left = args.shift
right = args.shift
if Puppet::FileSystem.exist?(left)
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def retrieve_node_facts(node, given_facts)
if facts.values.empty?
raise _("No facts available for target node: %{node}") % { node: node}
end

facts
end
end
2 changes: 2 additions & 0 deletions lib/puppet/application/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def preinit
Puppet::Type.typeloader.loadall(env)
Puppet::Type.eachtype do |t|
next if t.name == :component

types << t.name.to_s
end
puts types.sort
Expand Down Expand Up @@ -241,6 +242,7 @@ def find_or_save_resources(type, name, params)
if type == "file"
raise _("Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc")
end

Puppet::Resource.indirection.search( key, {} )
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def main
else
manifest = command_line.args.shift
raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)

Puppet.warning(_("Only one file can be used per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
end

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def main
puppet ssl clean --target <name>
END
end

clean(certname)
when 'bootstrap'
if !Puppet::Util::Log.sendlevel?(:info)
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/configurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def run_internal(options)
if tries > 3
raise Puppet::Error, _("Catalog environment didn't stabilize after %{tries} fetches, aborting run") % { tries: tries }
end

Puppet.notice _("Local environment: '%{local_env}' doesn't match server specified environment '%{catalog_env}', restarting agent run with environment '%{catalog_env}'") % { local_env: @environment, catalog_env: catalog.environment }
@environment = catalog.environment
report.environment = @environment
Expand All @@ -457,6 +458,7 @@ def run_internal(options)
# if we get here, ignore the cached catalog
catalog = prepare_and_retrieve_catalog(nil, facts, options, query_options)
return nil unless catalog

tries += 1
end

Expand Down Expand Up @@ -579,6 +581,7 @@ def last_server_specified_environment
if Puppet::FileSystem.exist?(Puppet[:lastrunfile])
summary = Puppet::Util::Yaml.safe_load_file(Puppet[:lastrunfile])
return [nil, nil] unless summary['application']['run_mode'] == 'agent'

initial_environment = summary['application']['initial_environment']
converged_environment = summary['application']['converged_environment']
@last_server_specified_environment = converged_environment if initial_environment != converged_environment
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/confine_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def summary
confines.each do |klass, list|
value = klass.summarize(list)
next if (value.respond_to?(:length) and value.length == 0) or (value == 0)

result[klass.name] = value

end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Puppet::Daemon

def initialize(agent, pidfile, scheduler = Puppet::Scheduler::Scheduler.new())
raise Puppet::DevError, _("Daemons must have an agent") unless agent

@scheduler = scheduler
@pidfile = pidfile
@agent = agent
Expand Down Expand Up @@ -80,6 +81,7 @@ def close_streams()

def reexec
raise Puppet::DevError, _("Cannot reexec unless ARGV arguments are set") unless argv

command = $0 + " " + argv.join(" ")
Puppet.notice "Restarting with '#{command}'"
stop(:exit => false)
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/datatypes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def initialize(type_name)

def create_type(loader)
raise ArgumentError, _('a data type must have an interface') unless @interface.is_a?(String)

created_type = Puppet::Pops::Types::PObjectType.new(
@type_name,
Puppet::Pops::Parser::EvaluatingParser.new.parse_string("{ #{@interface} }").body)
Expand Down Expand Up @@ -194,16 +195,19 @@ def initialize(type_builder)

def interface(type_string)
raise ArgumentError, _('a data type can only have one interface') unless @type_builder.interface.nil?

@type_builder.interface = type_string
end

def implementation(&block)
raise ArgumentError, _('a data type can only have one implementation') if @type_builder.has_implementation?

@type_builder.implementation = block
end

def implementation_class(ruby_class)
raise ArgumentError, _('a data type can only have one implementation') if @type_builder.has_implementation?

@type_builder.implementation_class = ruby_class
end

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def self.valid_file_checksum_types

def self.default_cadir
return "" if Puppet::Util::Platform.windows?

old_ca_dir = "#{Puppet[:ssldir]}/ca"
new_ca_dir = "/etc/puppetlabs/puppetserver/ca"

Expand Down Expand Up @@ -371,6 +372,7 @@ def self.initialize_default_settings!(settings)
paths = ENV['PATH'].split(File::PATH_SEPARATOR)
Puppet::Util::Platform.default_paths.each do |path|
next if paths.include?(path)

ENV['PATH'] = ENV['PATH'] + File::PATH_SEPARATOR + path
end
value
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def initialize(env_name, env_dir, environment)
# @!macro loader_get_conf
def get_conf(name)
return nil unless name.intern == @env_name

Puppet::Settings::EnvironmentConf.load_from(@env_dir, [])
end
end
Expand Down Expand Up @@ -268,6 +269,7 @@ def validated_directory(envdir)

def valid_environment_names
return [] unless Puppet::FileSystem.directory?(@environment_dir)

Puppet::FileSystem.children(@environment_dir).map do |child|
Puppet::FileSystem.basename_string(child).intern if validated_directory(child)
end.compact
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/etc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def puppet_etc_group_class
# :canonical_<member name> struct member.
def override_field_values_to_utf8(struct)
return nil if struct.nil?

new_struct = struct.is_a?(Etc::Passwd) ? puppet_etc_passwd_class.new : puppet_etc_group_class.new
struct.each_pair do |member, value|
if value.is_a?(String)
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/face/epp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
end
end
raise Puppet::Error, _("error while rendering epp") unless status

buffer.string
end
end
Expand Down Expand Up @@ -530,6 +531,7 @@ def create_compiler(options)
unless given_facts.instance_of?(Hash)
raise _("Incorrect formatted data in %{fact_file} given via the --facts flag") % { fact_file: fact_file }
end

# It is difficult to add to or modify the set of facts once the node is created
# as changes does not show up in parameters. Rather than manually patching up
# a node and risking future regressions, a new node is created from scratch
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/face/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
if Puppet::FileSystem.exist?(outputdir) && !Puppet::FileSystem.directory?(outputdir)
raise ArgumentError, _("The output directory '%{outputdir}' exists and is not a directory") % { outputdir: outputdir }
end

Puppet::FileSystem::mkpath(outputdir)

generator.generate(inputs, outputdir, options[:force])
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/face/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
if actionname
raise ArgumentError, _("The legacy subcommand '%{sub_command}' does not support supplying an action") % { sub_command: facename }
end

# legacy apps already emit ronn output
return render_application_help(facename)
else
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/face/module/changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
unless root_path
raise ArgumentError, _("Could not find a valid module at %{path}") % { path: path.inspect }
end

Puppet::ModuleTool::Applications::Checksummer.run(root_path, options)
end

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/face/module/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def warn_unmet_dependencies(environment)
def list_build_tree(list, ancestors=[], parent=nil, params={})
list.map do |mod|
next if @seen[(mod.forge_name or mod.name)]

node = list_build_node(mod, parent, params)
@seen[(mod.forge_name or mod.name)] = true

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/face/node/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def type_is_ensurable(resource)
type = environment.known_resource_types.find_definition(resource.restype)
return true if type && type.arguments.keys.include?('ensure')
end

return false
end
end
5 changes: 5 additions & 0 deletions lib/puppet/file_bucket/dipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def local?
def backup(file)
file_handle = Puppet::FileSystem.pathname(file)
raise(ArgumentError, _("File %{file} does not exist") % { file: file }) unless Puppet::FileSystem.exist?(file_handle)

begin
file_bucket_file = Puppet::FileBucket::File.new(file_handle, :bucket_path => @local_path)
files_original_path = absolutize_path(file)
Expand All @@ -61,6 +62,7 @@ def backup(file)
# Diffs two filebucket files identified by their sums
def diff(checksum_a, checksum_b, file_a, file_b)
raise RuntimeError, _("Diff is not supported on this platform") if Puppet[:diff] == ""

if checksum_a
source_path = "#{@rest_path}#{@checksum_type}/#{checksum_a}"
if checksum_b
Expand Down Expand Up @@ -95,6 +97,7 @@ def diff(checksum_a, checksum_b, file_a, file_b)
end
end
raise Puppet::Error, _("Failed to diff files") unless file_diff

file_diff.to_s
end

Expand All @@ -109,6 +112,7 @@ def get_bucket_file(sum)
file_bucket_file = Puppet::FileBucket::File.indirection.find(source_path, :bucket_path => @local_path)

raise Puppet::Error, _("File not found") unless file_bucket_file

file_bucket_file
end

Expand Down Expand Up @@ -164,6 +168,7 @@ def list(fromdate, todate)
:fromdate => fromdate,
:todate => todate)
raise Puppet::Error, _("File not found") unless file_bucket_list

file_bucket_list.to_s
end

Expand Down
Loading

0 comments on commit e44831f

Please sign in to comment.