utils: fix Rubocop warnings.

This commit is contained in:
Mike McQuaid 2016-09-11 17:47:04 +01:00
parent 8448fe17cb
commit 56b6c43686

View File

@ -138,12 +138,11 @@ def odeprecated(method, replacement = nil, options = {})
backtrace = options.fetch(:caller, caller)
tap_message = nil
caller_message = backtrace.detect do |line|
if line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/}
next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/}
tap = Tap.fetch $1
tap_message = "\nPlease report this to the #{tap} tap!"
true
end
end
caller_message ||= backtrace.detect do |line|
!line.start_with?("#{HOMEBREW_LIBRARY_PATH}/compat/")
end
@ -170,7 +169,7 @@ end
def pretty_installed(f)
if !$stdout.tty?
"#{f}"
f.to_s
elsif Emoji.enabled?
"#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}"
else
@ -180,7 +179,7 @@ end
def pretty_uninstalled(f)
if !$stdout.tty?
"#{f}"
f.to_s
elsif Emoji.enabled?
"#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}"
else
@ -196,7 +195,7 @@ def pretty_duration(s)
m = s / 60
s %= 60
res = "#{m} minute#{plural m}"
return res if s == 0
return res if s.zero?
res << " "
end
@ -204,7 +203,7 @@ def pretty_duration(s)
end
def plural(n, s = "s")
(n == 1) ? "" : s
n == 1 ? "" : s
end
def interactive_shell(f = nil)
@ -233,7 +232,11 @@ module Homebrew
pid = fork do
yield if block_given?
args.collect!(&:to_s)
exec(cmd, *args) rescue nil
begin
exec(cmd, *args)
rescue
nil
end
exit! 1 # never gets here unless exec failed
end
Process.wait(pid)
@ -291,7 +294,7 @@ module Homebrew
rescue Gem::SystemExitException => e
exit_code = e.exit_code
end
odie "Failed to install/update the '#{name}' gem." if exit_code != 0
odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero?
end
unless which executable
@ -542,10 +545,10 @@ def disk_usage_readable(size_in_bytes)
end
# avoid trailing zero after decimal point
if (size * 10).to_i % 10 == 0
if ((size * 10).to_i % 10).zero?
"#{size.to_i}#{unit}"
else
"#{"%.1f" % size}#{unit}"
"#{format("%.1f", size)}#{unit}"
end
end
@ -572,10 +575,10 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {})
glue_bytes = glue.encode("BINARY")
n_front_bytes = (max_bytes_in * front_weight).floor
n_back_bytes = max_bytes_in - n_front_bytes
if n_front_bytes == 0
if n_front_bytes.zero?
front = bytes[1..0]
back = bytes[-max_bytes_in..-1]
elsif n_back_bytes == 0
elsif n_back_bytes.zero?
front = bytes[0..(max_bytes_in - 1)]
back = bytes[1..0]
else