Skip to content

Commit

Permalink
[rubygems/rubygems] util/rubocop -A --only Style/FormatString
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and matzbot committed Apr 7, 2023
1 parent 84ce6fc commit 250e97c
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def self.time(msg, width = 0, display = Gem.configuration.verbose)

elapsed = Time.now - now

ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
ui.say format("%2$*1$s: %3$3.3fs", -width, msg, elapsed) if display

value
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/help_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def show_commands # :nodoc:
end

summary = wrap(summary, summary_width).split "\n"
out << sprintf(format, cmd_name, summary.shift)
out << format(format, cmd_name, summary.shift)
until summary.empty? do
out << "#{wrap_indent}#{summary.shift}"
end
Expand Down
6 changes: 2 additions & 4 deletions lib/rubygems/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ def hash # :nodoc:

def inspect # :nodoc:
if prerelease?
"<%s type=%p name=%p requirements=%p prerelease=ok>" %
[self.class, type, name, requirement.to_s]
format("<%s type=%p name=%p requirements=%p prerelease=ok>", self.class, type, name, requirement.to_s)
else
"<%s type=%p name=%p requirements=%p>" %
[self.class, type, name, requirement.to_s]
format("<%s type=%p name=%p requirements=%p>", self.class, type, name, requirement.to_s)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/dependency_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def find_name(full_name)
end

def inspect # :nodoc:
"%s %p>" % [super[0..-2], map(&:full_name)]
format("%s %p>", super[0..-2], map(&:full_name))
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def deprecate(name, repl, year, month)
msg = [
"NOTE: #{target}#{name} is deprecated",
repl == :none ? " with no replacement" : "; use #{repl} instead",
". It will be removed on or after %4d-%02d." % [year, month],
format(". It will be removed on or after %4d-%02d.", year, month),
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
]
warn "#{msg.join}." unless Gem::Deprecate.skip
Expand Down
6 changes: 1 addition & 5 deletions lib/rubygems/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ def add_platform(platform)
##
# A wordy description of the error.
def wordy
"Found %s (%s), but was for platform%s %s" %
[@name,
@version,
@platforms.size == 1 ? "" : "s",
@platforms.join(" ,")]
format("Found %s (%s), but was for platform%s %s", @name, @version, @platforms.size == 1 ? "" : "s", @platforms.join(" ,"))
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [
make_program = Shellwords.split(make_program_name)

# The installation of the bundled gems is failed when DESTDIR is empty in mswin platform.
destdir = /\bnmake/i !~ make_program_name || ENV["DESTDIR"] && ENV["DESTDIR"] != "" ? "DESTDIR=%s" % ENV["DESTDIR"] : ""
destdir = /\bnmake/i !~ make_program_name || ENV["DESTDIR"] && ENV["DESTDIR"] != "" ? format("DESTDIR=%s", ENV["DESTDIR"]) : ""

env = [destdir]

if sitedir
env << "sitearchdir=%s" % sitedir
env << "sitelibdir=%s" % sitedir
env << format("sitearchdir=%s", sitedir)
env << format("sitelibdir=%s", sitedir)
end

targets.each do |target|
Expand Down
6 changes: 2 additions & 4 deletions lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ def initialize(message, source = nil)

class PathError < Error
def initialize(destination, destination_dir)
super "installing into parent path %s of %s is not allowed" %
[destination, destination_dir]
super format("installing into parent path %s of %s is not allowed", destination, destination_dir)
end
end

class SymlinkError < Error
def initialize(name, destination, destination_dir)
super "installing symlink '%s' pointing to parent path %s of %s is not allowed" %
[name, destination, destination_dir]
super format("installing symlink '%s' pointing to parent path %s of %s is not allowed", name, destination, destination_dir)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/package/tar_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,6 @@ def header(checksum = @checksum)
end

def oct(num, len)
"%0#{len}o" % num
format("%0#{len}o", num)
end
end
4 changes: 1 addition & 3 deletions lib/rubygems/resolver/activation_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def full_spec
end

def inspect # :nodoc:
"#<%s for %p from %s>" % [
self.class, @spec, @request
]
format("#<%s for %p from %s>", self.class, @spec, @request)
end

##
Expand Down
12 changes: 2 additions & 10 deletions lib/rubygems/resolver/conflict.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def explanation
%s
MATCHING

matching = matching % [
dependency,
alternates.join(", "),
]
matching = format(matching, dependency, alternates.join(", "))
end

explanation = <<-EXPLANATION
Expand All @@ -82,12 +79,7 @@ def explanation
%s
EXPLANATION

explanation % [
activated, requirement,
request_path(@activated).reverse.join(", depends on\n "),
request_path(@failed_dep).reverse.join(", depends on\n "),
matching
]
format(explanation, activated, requirement, request_path(@activated).reverse.join(", depends on\n "), request_path(@failed_dep).reverse.join(", depends on\n "), matching)
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/resolver/index_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def hash
end

def inspect # :nodoc:
"#<%s %s source %s>" % [self.class, full_name, @source]
format("#<%s %s source %s>", self.class, full_name, @source)
end

def pretty_print(q) # :nodoc:
Expand Down
4 changes: 1 addition & 3 deletions lib/rubygems/resolver/installer_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ def prerelease=(allow_prerelease)
def inspect # :nodoc:
always_install = @always_install.map(&:full_name)

"#<%s domain: %s specs: %p always install: %p>" % [
self.class, @domain, @specs.keys, always_install
]
format("#<%s domain: %s specs: %p always install: %p>", self.class, @domain, @specs.keys, always_install)
end

##
Expand Down
7 changes: 2 additions & 5 deletions lib/rubygems/security/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,8 @@ def subject(certificate) # :nodoc:
end

def inspect # :nodoc:
"[Policy: %s - data: %p signer: %p chain: %p root: %p " \
"signed-only: %p trusted-only: %p]" % [
@name, @verify_chain, @verify_data, @verify_root, @verify_signer,
@only_signed, @only_trusted
]
format("[Policy: %s - data: %p signer: %p chain: %p root: %p " \
"signed-only: %p trusted-only: %p]", @name, @verify_chain, @verify_data, @verify_root, @verify_signer, @only_signed, @only_trusted)
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/source/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def <=>(other)

def inspect # :nodoc:
keys = @specs ? @specs.keys.sort : "NOT LOADED"
"#<%s specs: %p>" % [self.class, keys]
format("#<%s specs: %p>", self.class, keys)
end

def load_specs(type) # :nodoc:
Expand Down
10 changes: 2 additions & 8 deletions test/rubygems/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,10 @@ def parse_make_command_line_targets(line)
def assert_contains_make_command(target, output, msg = nil)
if output.include?("\n")
msg = build_message(msg,
"Expected output containing make command \"%s\", but was \n\nBEGIN_OF_OUTPUT\n%sEND_OF_OUTPUT" % [
("%s %s" % [make_command, target]).rstrip,
output,
])
format("Expected output containing make command \"%s\", but was \n\nBEGIN_OF_OUTPUT\n%sEND_OF_OUTPUT", format("%s %s", make_command, target).rstrip, output))
else
msg = build_message(msg,
'Expected make command "%s", but was "%s"' % [
("%s %s" % [make_command, target]).rstrip,
output,
])
format('Expected make command "%s", but was "%s"', format("%s %s", make_command, target).rstrip, output))
end

assert scan_make_command_lines(output).any? {|line|
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/package/tar_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def tar_file_contents(content)
end

def to_oct(n, pad_size)
"%0#{pad_size}o" % n
format("%0#{pad_size}o", n)
end

def util_entry(tar)
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_pristine_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_execute_env_shebang

assert_path_exist gem_exec

ruby_exec = sprintf Gem.default_exec_format, "ruby"
ruby_exec = format Gem.default_exec_format, "ruby"

bin_env = Gem.win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "

Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_setup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_env_shebang_flag
@cmd.options[:env_shebang] = true
@cmd.execute

ruby_exec = sprintf Gem.default_exec_format, "ruby"
ruby_exec = format Gem.default_exec_format, "ruby"

bin_env = Gem.win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
assert_match(/\A#!\s*#{bin_env}#{ruby_exec}/, File.read(default_gem_bin_path))
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def test_install
assert_path_exist exe

exe_mode = File.stat(exe).mode & 0111
assert_equal 0111, exe_mode, "0%o" % exe_mode unless Gem.win_platform?
assert_equal 0111, exe_mode, format("0%o", exe_mode) unless Gem.win_platform?

assert_path_exist File.join gemdir, "lib", "code.rb"

Expand Down

0 comments on commit 250e97c

Please sign in to comment.