Skip to content

Commit

Permalink
Merge pull request #9283 from AriaXLi/PUP-11993/more_style_cops
Browse files Browse the repository at this point in the history
(PUP-11993) The rest of the Style/Redundant* cops!
  • Loading branch information
joshcooper authored Mar 6, 2024
2 parents 5eaa95b + be334aa commit 62b1cd6
Show file tree
Hide file tree
Showing 289 changed files with 1,159 additions and 1,192 deletions.
13 changes: 0 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,19 +652,6 @@ Style/OptionalBooleanParameter:
Style/PreferredHashMethods:
Enabled: false

# This cop supports unsafe auto-correction (--auto-correct-all).
Style/RedundantInterpolation:
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).
Style/RedundantSelf:
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
14 changes: 7 additions & 7 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ def option(*options, &block)
define_method(fname, &block)
else
define_method(fname) do |value|
self.options["#{long}".to_sym] = value
self.options[long.to_s.to_sym] = value
end
end
self.option_parser_commands << [options, fname]
option_parser_commands << [options, fname]
end

def banner(banner = nil)
Expand Down 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 self.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 Expand Up @@ -330,7 +330,7 @@ def clear_everything_for_tests
# See also `lib/puppet/util/command_line.rb` for some special case early
# handling of this.
option("--version", "-V") do |_arg|
puts "#{Puppet.version}"
puts Puppet.version
exit(0)
end

Expand Down Expand Up @@ -553,14 +553,14 @@ def parse_options
self.class.option_parser_commands.each do |options, fname|
option_parser.on(*options) do |value|
# Call the method that "option()" created.
self.send(fname, value)
send(fname, value)
end
end

# Scan command line. We just hand any exceptions to our upper levels,
# rather than printing help and exiting, so that we can meaningfully
# respond with context-sensitive help if we want to. --daniel 2011-04-12
option_parser.parse!(self.command_line.args)
option_parser.parse!(command_line.args)
end

def handlearg(opt, val)
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/confine/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(values)
end

def message(value)
"facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'"
"facter value '#{test_value}' for '#{name}' not in required list '#{values.join(",")}'"
end

# Compare the passed-in value to the retrieved value.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/confine_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def confine(hash)
confine.name = test
@confines << confine
end
@confines[-1].label = self.label
@confines[-1].label = label
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/confiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def confine(hash)
# @api private
#
def confine_collection
@confine_collection ||= Puppet::ConfineCollection.new(self.to_s)
@confine_collection ||= Puppet::ConfineCollection.new(to_s)
end

# Checks whether this implementation is suitable for the current platform (or returns a summary
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/puppet/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def to_h
def self.from_issue_and_stack(issue, args = {})
filename, line = Puppet::Pops::PuppetStack.top_of_stack

self.new(
new(
issue.format(args),
filename,
line,
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/external/dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def initialize(params = {})
end

def to_s
(@name && @name != "" ? "<#{@name}>" : "") + "#{@label}"
(@name && @name != "" ? "<#{@name}>" : "") + @label.to_s
end
end

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/module/changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Puppet.warning _("%{count} files modified") % { count: return_value.size }
end
return_value.map do |changed_file|
"#{changed_file}"
changed_file.to_s
end.join("\n")
end
end
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
2 changes: 1 addition & 1 deletion lib/puppet/facter_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def load_external?
end

def load_external(value)
::Facter.load_external(value) if self.load_external?
::Facter.load_external(value) if load_external?
end

private
Expand Down
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
4 changes: 2 additions & 2 deletions lib/puppet/file_bucket/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def name
end

def self.from_binary(contents)
self.new(contents)
new(contents)
end

class StringContents
Expand Down 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
Loading

0 comments on commit 62b1cd6

Please sign in to comment.