Skip to content

Commit

Permalink
(PUP-11993) Style/RedundantSelf
Browse files Browse the repository at this point in the history
This commit enables the Style/RedundantSelf cop and fixes
675 autocorrectable offenses.
  • Loading branch information
AriaXLi committed Mar 6, 2024
1 parent 63295ed commit 4c20b77
Show file tree
Hide file tree
Showing 177 changed files with 624 additions and 628 deletions.
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,6 @@ Style/PreferredHashMethods:
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
8 changes: 4 additions & 4 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def option(*options, &block)
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 @@ -261,7 +261,7 @@ def find(application_name)
# @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
return const_defined?(class_name) ? const_get(class_name) : nil
end
private :try_load_class

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
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
2 changes: 1 addition & 1 deletion 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 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/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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def relative_path=(path)

# Stat our file, using the appropriate link-sensitive method.
def stat
@stat_method ||= self.links == :manage ? :lstat : :stat
@stat_method ||= links == :manage ? :lstat : :stat
Puppet::FileSystem.send(@stat_method, full_path)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/fileset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ def valid?(path)

def continue_recursion_at?(depth)
# recurse if told to, and infinite recursion or current depth not at the limit
self.recurse && (self.recurselimit == :infinite || depth <= self.recurselimit)
recurse && (recurselimit == :infinite || depth <= recurselimit)
end
end
2 changes: 1 addition & 1 deletion lib/puppet/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def initialize(source, data)
end

def install(dir)
staging_dir = self.prepare
staging_dir = prepare

module_dir = dir + name[/-(.*)/, 1]
module_dir.rmtree if module_dir.exist?
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/forge/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ForgeError < Puppet::Error
#
# @return [String] the multiline version of the error message
def multiline
self.message
message
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def dispatch(meth_name, argument_mismatch_handler, &block)
@block_name = nil
@return_type = nil
@argument_mismatch_hander = argument_mismatch_handler
self.instance_eval(&block)
instance_eval(&block)
callable_t = create_callable(@types, @block_type, @return_type, @min, @max)
@dispatcher.add(Puppet::Pops::Functions::Dispatch.new(callable_t, meth_name, @names, @max == :default, @block_name, @injections, @weaving, @argument_mismatch_hander))
end
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/http/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Puppet::HTTP::Proxy
def self.proxy(uri)
if http_proxy_host && !no_proxy?(uri)
Net::HTTP.new(uri.host, uri.port, self.http_proxy_host, self.http_proxy_port, self.http_proxy_user, self.http_proxy_password)
Net::HTTP.new(uri.host, uri.port, http_proxy_host, http_proxy_port, http_proxy_user, http_proxy_password)
else
http = Net::HTTP.new(uri.host, uri.port, nil, nil, nil, nil)
# Net::HTTP defaults the proxy port even though we said not to
Expand Down Expand Up @@ -72,7 +72,7 @@ def self.no_proxy?(dest)
end

def self.http_proxy_host
env = self.http_proxy_env
env = http_proxy_env

if env and env.host
return env.host
Expand All @@ -86,7 +86,7 @@ def self.http_proxy_host
end

def self.http_proxy_port
env = self.http_proxy_env
env = http_proxy_env

if env and env.port
return env.port
Expand All @@ -96,7 +96,7 @@ def self.http_proxy_port
end

def self.http_proxy_user
env = self.http_proxy_env
env = http_proxy_env

if env and env.user
return env.user
Expand All @@ -110,7 +110,7 @@ def self.http_proxy_user
end

def self.http_proxy_password
env = self.http_proxy_env
env = http_proxy_env

if env and env.password
return env.password
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/http/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Puppet::HTTP::Site
attr_reader :scheme, :host, :port

def self.from_uri(uri)
self.new(uri.scheme, uri.host, uri.port)
new(uri.scheme, uri.host, uri.port)
end

def initialize(scheme, host, port)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/indirector/facts/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def search(request)
private

def json_dir_path
self.path("*")
path("*")
end
end
32 changes: 16 additions & 16 deletions lib/puppet/indirector/indirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def set_global_setting(setting, value)

# Set up our request object.
def request(*args)
Puppet::Indirector::Request.new(self.name, *args)
Puppet::Indirector::Request.new(name, *args)
end

# Return the singleton terminus for this indirection.
def terminus(terminus_name = nil)
# Get the name of the terminus.
raise Puppet::DevError, _("No terminus specified for %{name}; cannot redirect") % { name: self.name } unless terminus_name ||= terminus_class
raise Puppet::DevError, _("No terminus specified for %{name}; cannot redirect") % { name: name } unless terminus_name ||= terminus_class

termini[terminus_name] ||= make_terminus(terminus_name)
end
Expand All @@ -158,11 +158,11 @@ def terminus_setting=(setting)
# Determine the terminus class.
def terminus_class
unless @terminus_class.value
setting = self.terminus_setting
setting = terminus_setting
if setting
self.terminus_class = Puppet.settings[setting]
else
raise Puppet::DevError, _("No terminus class nor terminus setting was provided for indirection %{name}") % { name: self.name }
raise Puppet::DevError, _("No terminus class nor terminus setting was provided for indirection %{name}") % { name: name }
end
end
@terminus_class.value
Expand All @@ -184,9 +184,9 @@ def validate_terminus_class(terminus_class)
raise ArgumentError, _("Invalid terminus name %{terminus_class}") % { terminus_class: terminus_class.inspect }
end

unless Puppet::Indirector::Terminus.terminus_class(self.name, terminus_class)
unless Puppet::Indirector::Terminus.terminus_class(name, terminus_class)
raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{name}") %
{ terminus_class: terminus_class, name: self.name }
{ terminus_class: terminus_class, name: name }
end
end

Expand All @@ -201,7 +201,7 @@ def expire(key, options = {})
instance = cache.find(request(:find, key, nil, options))
return nil unless instance

Puppet.info _("Expiring the %{cache} cache of %{instance}") % { cache: self.name, instance: instance.name }
Puppet.info _("Expiring the %{cache} cache of %{instance}") % { cache: name, instance: instance.name }

# Set an expiration date in the past
instance.expiration = Time.now - 60
Expand Down Expand Up @@ -229,9 +229,9 @@ def find(key, options = {})
# appropriate.
result = terminus.find(request)
unless result.nil?
result.expiration ||= self.expiration if result.respond_to?(:expiration)
result.expiration ||= expiration if result.respond_to?(:expiration)
if cache? && !request.ignore_cache_save?
Puppet.info _("Caching %{indirection} for %{request}") % { indirection: self.name, request: request.key }
Puppet.info _("Caching %{indirection} for %{request}") % { indirection: name, request: request.key }
begin
cache.save request(:save, key, result, options)
rescue => detail
Expand All @@ -242,7 +242,7 @@ def find(key, options = {})

filtered = result
if terminus.respond_to?(:filter)
Puppet::Util::Profiler.profile(_("Filtered result for %{indirection} %{request}") % { indirection: self.name, request: request.key }, [:indirector, :filter, self.name, request.key]) do
Puppet::Util::Profiler.profile(_("Filtered result for %{indirection} %{request}") % { indirection: name, request: request.key }, [:indirector, :filter, name, request.key]) do
filtered = terminus.filter(result)
rescue Puppet::Error => detail
Puppet.log_exception(detail)
Expand Down Expand Up @@ -271,14 +271,14 @@ def find_in_cache(request)
return nil unless cached

if cached.expired?
Puppet.info _("Not using expired %{indirection} for %{request} from cache; expired at %{expiration}") % { indirection: self.name, request: request.key, expiration: cached.expiration }
Puppet.info _("Not using expired %{indirection} for %{request} from cache; expired at %{expiration}") % { indirection: name, request: request.key, expiration: cached.expiration }
return nil
end

Puppet.debug { "Using cached #{self.name} for #{request.key}" }
Puppet.debug { "Using cached #{name} for #{request.key}" }
cached
rescue => detail
Puppet.log_exception(detail, _("Cached %{indirection} for %{request} failed: %{detail}") % { indirection: self.name, request: request.key, detail: detail })
Puppet.log_exception(detail, _("Cached %{indirection} for %{request} failed: %{detail}") % { indirection: name, request: request.key, detail: detail })
nil
end

Expand Down Expand Up @@ -309,7 +309,7 @@ def search(key, options = {})
result.each do |instance|
next unless instance.respond_to? :expiration

instance.expiration ||= self.expiration
instance.expiration ||= expiration
end
return result
end
Expand Down Expand Up @@ -371,9 +371,9 @@ def prepare(request)
# Create a new terminus instance.
def make_terminus(terminus_class)
# Load our terminus class.
klass = Puppet::Indirector::Terminus.terminus_class(self.name, terminus_class)
klass = Puppet::Indirector::Terminus.terminus_class(name, terminus_class)
unless klass
raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{indirection}") % { terminus_class: terminus_class, indirection: self.name }
raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{indirection}") % { terminus_class: terminus_class, indirection: name }
end

klass.new
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/indirector/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def save(request)

Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_json(request.instance).force_encoding(Encoding::BINARY) }
rescue TypeError => detail
Puppet.log_exception(detail, _("Could not save %{json} %{request}: %{detail}") % { json: self.name, request: request.key, detail: detail })
Puppet.log_exception(detail, _("Could not save %{json} %{request}: %{detail}") % { json: name, request: request.key, detail: detail })
end

def destroy(request)
Puppet::FileSystem.unlink(path(request.key))
rescue => detail
unless detail.is_a? Errno::ENOENT
raise Puppet::Error, _("Could not destroy %{json} %{request}: %{detail}") % { json: self.name, request: request.key, detail: detail }, detail.backtrace
raise Puppet::Error, _("Could not destroy %{json} %{request}: %{detail}") % { json: name, request: request.key, detail: detail }, detail.backtrace
end

1 # emulate success...
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/indirector/msgpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def save(request)

Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_msgpack(request.instance) }
rescue TypeError => detail
Puppet.log_exception(detail, _("Could not save %{name} %{request}: %{detail}") % { name: self.name, request: request.key, detail: detail })
Puppet.log_exception(detail, _("Could not save %{name} %{request}: %{detail}") % { name: name, request: request.key, detail: detail })
end

def destroy(request)
Puppet::FileSystem.unlink(path(request.key))
rescue => detail
unless detail.is_a? Errno::ENOENT
raise Puppet::Error, _("Could not destroy %{name} %{request}: %{detail}") % { name: self.name, request: request.key, detail: detail }, detail.backtrace
raise Puppet::Error, _("Could not destroy %{name} %{request}: %{detail}") % { name: name, request: request.key, detail: detail }, detail.backtrace
end

1 # emulate success...
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/indirector/report/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def save(request)
fh.print JSON.dump(request.instance)
end
rescue TypeError => detail
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail }
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail }
end
end
end
2 changes: 1 addition & 1 deletion lib/puppet/indirector/report/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def save(request)
fh.print YAML.dump(request.instance)
end
rescue TypeError => detail
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail }
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail }
end
end
end
2 changes: 1 addition & 1 deletion lib/puppet/indirector/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def description
end

def remote?
self.node or self.ip
node or ip
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/indirector/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def save(request)
begin
Puppet::Util::Yaml.dump(request.instance, file)
rescue TypeError => detail
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail }
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail }
end
end

Expand Down
Loading

0 comments on commit 4c20b77

Please sign in to comment.