Skip to content

Commit

Permalink
(PUP-11993) Style/RedundantInterpolation
Browse files Browse the repository at this point in the history
This commit enables the Style/RedundantInterpolation cop and fixes
35 (unsafe) autocorrectable offenses.
  • Loading branch information
AriaXLi committed Mar 6, 2024
1 parent 5eaa95b commit d51f733
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 32 deletions.
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +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:
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ 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]
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
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
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/http/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.no_proxy?(dest)
dest_string = "#{dest.host}:#{dest.port}"
else
no_proxy_regex = /#{host}$/
dest_string = "#{dest.host}"
dest_string = dest.host.to_s
end

if no_proxy_regex.match(dest_string)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/module_tool/applications/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def resolve_install_conflicts(graph, is_dependency = false)
:version => release[:version][:vstring]
}
dependency = is_dependency ? dependency_info : nil
all_versions = @versions["#{@module_name}"].sort_by { |h| h[:semver] }
all_versions = @versions[@module_name.to_s].sort_by { |h| h[:semver] }
versions = all_versions.select { |x| x[:semver].special == '' }
versions = all_versions if versions.empty?
latest_version = versions.last[:vstring]
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/module_tool/errors/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def vstring
if @action == :upgrade
"#{v(@installed_version)} -> #{v(@requested_version)}"
else
"#{v(@installed_version || @requested_version)}"
v(@installed_version || @requested_version).to_s
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/module_tool/shared_behaviors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a
next if range === seen[mod][:semver]

req_module = @module_name
req_versions = @versions["#{@module_name}"].map { |v| v[:semver] }
req_versions = @versions[@module_name.to_s].map { |v| v[:semver] }
raise InvalidDependencyCycleError,
:module_name => mod,
:source => (source + [{ :name => mod, :version => source.last[:dependency] }]),
Expand All @@ -121,14 +121,14 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a
@conditions.each { |_, conds| conds.delete_if { |c| c[:module] == mod } }
end

versions = @versions["#{mod}"].select { |h| range === h[:semver] }
versions = @versions[mod.to_s].select { |h| range === h[:semver] }
valid_versions = versions.select { |x| x[:semver].special == '' }
valid_versions = versions if valid_versions.empty?

version = valid_versions.last
unless version
req_module = @module_name
req_versions = @versions["#{@module_name}"].map { |v| v[:semver] }
req_versions = @versions[@module_name.to_s].map { |v| v[:semver] }
raise NoVersionsSatisfyError,
:requested_name => req_module,
:requested_version => @version || annotated_version(req_module, req_versions),
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/network/formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def flatten_array(array)
a["#{i}.#{el_k}"] = el_v
end
else
a["#{i}"] = el
a[i.to_s] = el
end
end
a
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/serialization/abstract_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def register_types
end

def to_s
"#{self.class.name}"
self.class.name.to_s
end

def inspect
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/property/keyvalue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def insync?(is)

next if value.is_a?(Hash)

unless value.include?("#{separator}")
unless value.include?(separator.to_s)
raise ArgumentError, _("Key/value pairs must be separated by '%{separator}'") % { separator: separator }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/aix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def latest
upd = latest_info

unless upd.nil?
return "#{upd[:version]}"
return (upd[:version]).to_s
else
raise Puppet::DevError, _("Tried to get latest on a missing package") if properties[:ensure] == :absent

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def install(useversion = true)
command_options << source
else
# interpret it as a gem repository
command_options << "--source" << "#{source}" << resource[:name]
command_options << "--source" << source.to_s << resource[:name]
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def available_versions_with_old_pip
self.class.validate_command(command)

Dir.mktmpdir("puppet_pip") do |dir|
command_and_options = [self.class.quote(command), 'install', "#{@resource[:name]}", '-d', "#{dir}", '-v']
command_and_options = [self.class.quote(command), 'install', (@resource[:name]).to_s, '-d', dir.to_s, '-v']
command_and_options << install_options if @resource[:install_options]
execpipe command_and_options do |process|
process.collect do |line|
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/package/portage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def qatom
when true, false, Symbol
search = @resource[:name]
else
search = '=' + @resource[:name] + '-' + "#{should}"
search = '=' + @resource[:name] + '-' + should.to_s
end
search_output = qatom_bin(*[search, '--format', output_format])
# verify if the search found anything
Expand Down Expand Up @@ -179,7 +179,7 @@ def query

if @resource[:name] =~ /^@/
if package_sets.include?(@resource[:name][1..].to_s)
return({ :name => "#{@resource[:name]}", :ensure => '9999', :version_available => nil, :installed_versions => nil, :installable_versions => "9999," })
return({ :name => (@resource[:name]).to_s, :ensure => '9999', :version_available => nil, :installed_versions => nil, :installable_versions => "9999," })
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/puppetserver_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def install(useversion = true)
raise Puppet::Error, _('puppet:// URLs are not supported as gem sources')
else
# interpret it as a gem repository
command_options << '--source' << "#{resource[:source]}" << resource[:name]
command_options << '--source' << resource[:source].to_s << resource[:name]
end
else
command_options << resource[:name]
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def query
# NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value
# IF YOU CALL THIS METHOD, IT WILL CALL RPM
# Use get(:property) to check if cached values are available
cmd = ["-q", @resource[:name], "#{self.class.nosignature}", "#{self.class.nodigest}", "--qf", "#{self.class::NEVRA_FORMAT}"]
cmd = ["-q", @resource[:name], self.class.nosignature.to_s, self.class.nodigest.to_s, "--qf", self.class::NEVRA_FORMAT.to_s]

begin
output = rpm(*cmd)
Expand Down Expand Up @@ -114,7 +114,7 @@ def latest
@resource.fail _("RPMs must specify a package source")
end

cmd = [command(:rpm), "-q", "--qf", "#{self.class::NEVRA_FORMAT}", "-p", source]
cmd = [command(:rpm), "-q", "--qf", self.class::NEVRA_FORMAT.to_s, "-p", source]
h = self.class.nevra_to_multiversion_hash(execute(cmd))
h[:ensure]
rescue Puppet::ExecutionFailure => e
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/service/daemontools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def setupservice
if resource[:manifest]
Puppet.notice "Configuring #{resource[:name]}"
command = [resource[:manifest], resource[:name]]
system("#{command}")
system(command.to_s)
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error.new("Cannot config #{self.service} to enable it: #{detail}", detail)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/user/hpux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def modifycmd(param, value)
cmd << "/usr/lbin/modprpw"
cmd << "-v"
cmd << "-l"
cmd << "#{resource.name}"
cmd << resource.name.to_s
end
cmd
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/resource/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def write_resource_file
to_print = resources.filter_map do |resource|
next unless resource.managed?

"#{resource.ref.downcase}"
resource.ref.downcase.to_s
end
f.puts to_print.join("\n")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

# Make sure we convert to an array.
munge do |value|
fail _("Tidy can't use matches with recurse 0, false, or undef") if "#{@resource[:recurse]}" =~ /^(0|false|)$/
fail _("Tidy can't use matches with recurse 0, false, or undef") if (@resource[:recurse]).to_s =~ /^(0|false|)$/

[value].flatten
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/package/version/range/eq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Puppet::Util::Package::Version
class Range
class Eq < Simple
def to_s
"#{@version}"
@version.to_s
end

def include?(version)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/rdoc/generators/puppet_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ def section
end

def index_name
"#{@context.name}"
@context.name.to_s
end

def params
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/windows/sid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def name_to_principal(name, allow_unresolved = false)

raw_sid_bytes ? Principal.lookup_account_sid(raw_sid_bytes) : Principal.lookup_account_name(name)
rescue => e
Puppet.debug("#{e.message}")
Puppet.debug(e.message.to_s)
(allow_unresolved && raw_sid_bytes) ? unresolved_principal(name, raw_sid_bytes) : nil
end
module_function :name_to_principal
Expand Down

0 comments on commit d51f733

Please sign in to comment.