Skip to content

Commit

Permalink
(PUP-11993) Style/RedundantReturn
Browse files Browse the repository at this point in the history
This commit enables the Style/RedundantReturn cop and fixes 241
autocorrectable offenses.
  • Loading branch information
AriaXLi committed Mar 6, 2024
1 parent 4c20b77 commit 0b954ad
Show file tree
Hide file tree
Showing 200 changed files with 527 additions and 552 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,6 @@ Style/OptionalBooleanParameter:
Style/PreferredHashMethods:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Expand Down
6 changes: 3 additions & 3 deletions lib/hiera/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def compiler

def find_hostclass(scope)
if scope.source and scope.source.type == :hostclass
return scope.source.name.downcase
scope.source.name.downcase
elsif scope.parent
return find_hostclass(scope.parent)
find_hostclass(scope.parent)
else
return nil
nil
end
end
private :find_hostclass
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera_puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def parse_args(args)
default = args[1]
override = args[2]

return [key, default, override]
[key, default, override]
end

def hiera
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def self.replace_settings_object(new_settings)
# @api public
def self.[](param)
if param == :debug
return Puppet::Util::Log.level == :debug
Puppet::Util::Log.level == :debug
else
return @@settings[param]
@@settings[param]
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ def find(application_name)
raise Puppet::Error, _("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name }
end

return clazz
clazz
end

# Given the fully qualified name of a class, attempt to get the class instance.
# @param [String] class_name the fully qualified name of the class to try to load
# @return [Class] the Class instance, or nil? if it could not be loaded.
def try_load_class(class_name)
return const_defined?(class_name) ? const_get(class_name) : nil
const_defined?(class_name) ? const_get(class_name) : nil
end
private :try_load_class

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/application/describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def scrub(text)
# indent from every line.
if text =~ /^(\s+)/
indent = ::Regexp.last_match(1)
return text.gsub(/^#{indent}/, '')
text.gsub(/^#{indent}/, '')
else
return text
text
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/application/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def handle_unknown(opt, arg)
end

def run_command
return [:rdoc].include?(options[:mode]) ? send(options[:mode]) : other
[:rdoc].include?(options[:mode]) ? send(options[:mode]) : other
end

def rdoc
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/application/face_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def find_global_settings_argument(item)
pattern.match item and return object
end
end
return nil # nothing found.
nil # nothing found.
end

def find_application_argument(item)
Expand All @@ -181,7 +181,7 @@ def find_application_argument(item)
}
end
end
return nil # not found
nil # not found
end

def setup
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/application/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def download_cert(ssl_context)
cert
rescue Puppet::HTTP::ResponseError => e
if e.response.code == 404
return nil
nil
else
raise Puppet::Error.new(_("Failed to download certificate: %{message}") % { message: e.message }, e)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/configurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def run_internal(options)
true
rescue => detail
Puppet.log_exception(detail, _("Failed to apply catalog: %{detail}") % { detail: detail })
return nil
nil
ensure
execute_postrun_command or return nil # rubocop:disable Lint/EnsureReturn
end
Expand Down Expand Up @@ -675,12 +675,12 @@ def resubmit_facts

puppet.put_facts(facts.name, facts: facts, environment: Puppet.lookup(:current_environment).name.to_s)

return true
true
rescue => detail
Puppet.log_exception(detail, _("Failed to submit facts: %{detail}") %
{ detail: detail })

return false
false
end

private
Expand Down Expand Up @@ -722,7 +722,7 @@ def retrieve_catalog_from_cache(query_options)
result
rescue => detail
Puppet.log_exception(detail, _("Could not retrieve catalog from cache: %{detail}") % { detail: detail })
return nil
nil
end

def retrieve_new_catalog(facts, query_options)
Expand All @@ -744,7 +744,7 @@ def retrieve_new_catalog(facts, query_options)
result
rescue StandardError => detail
Puppet.log_exception(detail, _("Could not retrieve catalog from remote server: %{detail}") % { detail: detail })
return nil
nil
end

def download_plugins(remote_environment_for_plugins)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/configurer/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ def default_arguments
defargs[:owner] = Process.uid
defargs[:group] = Process.gid
end
return defargs
defargs
end
end
2 changes: 1 addition & 1 deletion lib/puppet/confine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def valid?
end
end

return true
true
ensure
reset
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/confiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def confine_collection
# @api public
#
def suitable?(short = true)
return(short ? confine_collection.valid? : confine_collection.summary)
(short ? confine_collection.valid? : confine_collection.summary)
end
end
2 changes: 1 addition & 1 deletion lib/puppet/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def self.real_path(dir)
if Puppet::FileSystem.symlink?(dir) && Puppet[:versioned_environment_dirs]
dir = Pathname.new Puppet::FileSystem.expand_path(Puppet::FileSystem.readlink(dir))
end
return dir
dir
end

# @!macro loader_search_paths
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/face/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def render_face_man(facename)
end

def render_application_help(applicationname)
return Puppet::Application[applicationname].help
Puppet::Application[applicationname].help
rescue StandardError, LoadError => detail
message = []
message << _('Could not load help for the application %{application_name}.') % { application_name: applicationname }
Expand All @@ -107,7 +107,7 @@ def render_application_help(applicationname)

def render_face_help(facename, actionname, version)
face, action = load_face_help(facename, actionname, version)
return template_for(face, action).result(binding)
template_for(face, action).result(binding)
rescue StandardError, LoadError => detail
message = []
message << _('Could not load help for the face %{face_name}.') % { face_name: facename }
Expand Down Expand Up @@ -141,7 +141,7 @@ def erb(name)
template = (Pathname(__FILE__).dirname + "help" + name)
erb = Puppet::Util.create_erb(template.read)
erb.filename = template.to_s
return erb
erb
end

# Return a list of applications that are not simply just stubs for Faces.
Expand Down Expand Up @@ -213,7 +213,7 @@ def horribly_extract_summary_from(appname)
return md[1]
end
end
return ''
''
end
# This should absolutely be a private method, but for some reason it appears
# that you can't use the 'private' keyword inside of a Face definition.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/face/node/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ def type_is_ensurable(resource)
return true if type && type.arguments.keys.include?('ensure')
end

return false
false
end
end
6 changes: 3 additions & 3 deletions lib/puppet/file_bucket/dipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def backup(file)
Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path)
end

return file_bucket_file.checksum_data
file_bucket_file.checksum_data
rescue => detail
message = _("Could not back up %{file}: %{detail}") % { file: file, detail: detail }
Puppet.log_exception(detail, message)
Expand Down Expand Up @@ -152,9 +152,9 @@ def restore(file, sum)
Puppet.err _("Could not find file with checksum %{sum}") % { sum: sum }
return nil
end
return newsum
newsum
else
return nil
nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_bucket/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def checksum_data(base_method)
def to_binary
# This is not so horrible as for FileContent, but still possible to mutate the content that the
# checksum is based on... so semi horrible...
return @contents;
@contents;
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/file_serving/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Puppet::FileServing::Base
# Does our file exist?
def exist?
stat
return true
true
rescue
return false
false
end

# Return the full path to our file. Fails if there's no path set.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def split_path(request)
path = path.gsub(%r{/+}, "/")
end

return mount, path
[mount, path]
end

def umount(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize(stat, path, source_permissions)
:group => 'S-1-0-0',
:mode => 0o644 }.each do |method, default_value|
define_method method do
return default_value
default_value
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/file_serving/mount/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def find(short_file, request)
# Return the path as appropriate, expanding as necessary.
def path(node = nil)
if expandable?
return expand(@path, node)
expand(@path, node)
else
return @path
@path
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_system/memory_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def open(path, *args, &block)
if block_given?
yield handle
else
return handle
handle
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_system/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def expand_path(path, dir_string = nil)
end

def exist?(path)
return Puppet::Util::Windows::File.exist?(path)
Puppet::Util::Windows::File.exist?(path)
end

def symlink(path, dest, options = {})
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def fetch(input)
uri = decode_uri(response['pagination']['next'])
end

return releases
releases
end

def make_http_request(*args)
Expand Down Expand Up @@ -161,7 +161,7 @@ def install(dir)

# Return the Pathname object representing the directory where the
# module release archive was unpacked the to.
return module_dir
module_dir
ensure
staging_dir.rmtree if staging_dir.exist?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/forge/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def retrieve(url)

# Return contents of file at the given URI's +uri+.
def read_retrieve(uri)
return uri.read
uri.read
end

# Return Pathname for repository's cache directory, create it if needed.
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/forge/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def forge_authorization
# repository at +release+ (e.g. "myuser-mymodule").
def retrieve(release)
path = @host.chomp('/') + release
return cache.retrieve(path)
cache.retrieve(path)
end

# Return the URI string for this repository.
Expand All @@ -80,7 +80,7 @@ def to_s
# Return the cache key for this repository, this a hashed string based on
# the URI.
def cache_key
return @cache_key ||= [
@cache_key ||= [
@host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''),
Digest::SHA1.hexdigest(@host.to_s)
].join('-').freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def call(scope, *args, &block)
# this is the scope.function_xxx(...) call
return scope.send(self.class.method3x, mapped_args)
end
return result.value
result.value
rescue Puppet::Pops::Evaluator::Next => jumper
begin
throw :next, jumper.value
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def on_error(a, b, *ignore_case)

if a.class != b.class
# TRANSLATORS 'compare' is a name
return _("compare(): Can only compare values of the same type (or for Timestamp/Timespan also against Numeric). Got %{type_a} and %{type_b}") % {
_("compare(): Can only compare values of the same type (or for Timestamp/Timespan also against Numeric). Got %{type_a} and %{type_b}") % {
type_a: type_label(a), type_b: type_label(b)
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions/get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_from_value(value, navigation, default_value = nil, &block)

begin
result = call_function('dig', value, *segments)
return result.nil? ? default_value : result
result.nil? ? default_value : result
rescue Puppet::ErrorWithData => e
if block_given?
yield(e.error_data)
Expand Down
Loading

0 comments on commit 0b954ad

Please sign in to comment.