Skip to content

Commit

Permalink
Fix some auto-correctable type errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Nov 29, 2020
1 parent cf169e5 commit 6750448
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def fixopt(f)
args = Homebrew.install_args.parse
Context.current = args.context

error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

trap("INT", old_trap)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.description
def run
require "diagnostic"

success = true
success = T.let(true, T::Boolean)

checks = Homebrew::Diagnostic::Checks.new(verbose: true)
checks.cask_checks.each do |check|
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/--env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __env
BuildEnvironment.dump ENV
else
BuildEnvironment.keys(ENV).each do |key|
puts Utils::Shell.export_value(key, ENV[key], shell)
puts Utils::Shell.export_value(key, ENV.fetch(key), shell)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def bottle_formula(f, args:)

formula_and_runtime_deps_names = [f.name] + f.runtime_dependencies.map(&:name)
keg = Keg.new(f.prefix)
relocatable = false
skip_relocation = false
relocatable = T.let(false, T::Boolean)
skip_relocation = T.let(false, T::Boolean)

keg.lock do
original_tab = nil
Expand Down Expand Up @@ -472,7 +472,7 @@ def merge(args:)

if args.write?
path = Pathname.new((HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]).to_s)
update_or_add = nil
update_or_add = T.let(nil, T.nilable(String))

Utils::Inreplace.inreplace(path) do |s|
if s.inreplace_string.include? "bottle do"
Expand Down
9 changes: 8 additions & 1 deletion Library/Homebrew/dev-cmd/typecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ def typecheck
srb_exec = %w[bundle exec srb tc]
srb_exec << "--error-black-list" << "5061"
srb_exec << "--quiet" if args.quiet?
srb_exec << "--autocorrect" if args.fix?

if args.fix?
# Auto-correcting method names is almost always wrong.
srb_exec << "--error-black-list" << "7003"

srb_exec << "--autocorrect"
end

srb_exec += ["--ignore", args.ignore] if args.ignore.present?
if args.file.present? || args.dir.present?
cd("sorbet")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def move_to_new_directory
return unless old_cellar.exist?

if new_cellar.exist?
conflicted = false
conflicted = T.let(false, T::Boolean)
old_cellar.each_child do |c|
next unless (new_cellar/c.basename).exist?

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/missing_formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def disallowed_reason(name)
alias generic_disallowed_reason disallowed_reason

def tap_migration_reason(name)
message = nil
message = T.let(nil, T.nilable(String))

Tap.each do |old_tap|
new_tap = old_tap.tap_migrations[name]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/postinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

begin
args = Homebrew.postinstall_args.parse
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

trap("INT", old_trap)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Readall
class << self
def valid_ruby_syntax?(ruby_files)
failed = false
failed = T.let(false, T::Boolean)
ruby_files.each do |ruby_file|
# As a side effect, print syntax errors/warnings to `$stderr`.
failed = true if syntax_errors_or_warnings?(ruby_file)
Expand All @@ -21,7 +21,7 @@ def valid_ruby_syntax?(ruby_files)
def valid_aliases?(alias_dir, formula_dir)
return true unless alias_dir.directory?

failed = false
failed = T.let(false, T::Boolean)
alias_dir.each_child do |f|
if !f.symlink?
onoe "Non-symlink alias: #{f}"
Expand All @@ -40,7 +40,7 @@ def valid_aliases?(alias_dir, formula_dir)
end

def valid_formulae?(formulae)
success = true
success = T.let(true, T::Boolean)
formulae.each do |file|
Formulary.factory(file)
rescue Interrupt
Expand All @@ -54,7 +54,7 @@ def valid_formulae?(formulae)
end

def valid_casks?(casks)
success = true
success = T.let(true, T::Boolean)
casks.each do |file|
Cask::CaskLoader.load(file)
rescue Interrupt
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/deprecate_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)

next if node.nil?

reason_found = false
reason_found = T.let(false, T::Boolean)
reason(node) do |reason_node|
reason_found = true
next if reason_node.sym_type?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
args = Homebrew.test_args.parse
Context.current = args.context

error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

trap("INT", old_trap)
Expand Down
23 changes: 13 additions & 10 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _system(cmd, *args, **options)
end
exit! 1 # never gets here unless exec failed
end
Process.wait(pid)
Process.wait(T.must(pid))
$CHILD_STATUS.success?
end

Expand All @@ -58,10 +58,13 @@ def inject_dump_stats!(the_module, pattern)
method = instance_method(name)
define_method(name) do |*args, &block|
time = Time.now
method.bind(self).call(*args, &block)
ensure
$times[name] ||= 0
$times[name] += Time.now - time

begin
method.bind(self).call(*args, &block)
ensure
$times[name] ||= 0
$times[name] += Time.now - time
end
end
end
end
Expand Down Expand Up @@ -190,7 +193,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call
line.include?("/.metadata/")
end

tap_message = nil
tap_message = T.let(nil, T.nilable(String))

backtrace.each do |line|
next unless match = line.match(HOMEBREW_TAP_PATH_REGEX)
Expand Down Expand Up @@ -263,12 +266,12 @@ def interactive_shell(f = nil)
ENV["HOMEBREW_DEBUG_INSTALL"] = f.full_name
end

if ENV["SHELL"].include?("zsh") && ENV["HOME"].start_with?(HOMEBREW_TEMP.resolved_path.to_s)
FileUtils.mkdir_p ENV["HOME"]
FileUtils.touch "#{ENV["HOME"]}/.zshrc"
if ENV["SHELL"].include?("zsh") && (home = ENV["HOME"])&.start_with?(HOMEBREW_TEMP.resolved_path.to_s)
FileUtils.mkdir_p home
FileUtils.touch "#{home}/.zshrc"
end

Process.wait fork { exec ENV["SHELL"] }
Process.wait fork { exec ENV.fetch("SHELL") }

return if $CHILD_STATUS.success?
raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def report(type, metadata = {})
"--silent", "--output", "/dev/null",
"https://www.google-analytics.com/collect"
end
Process.detach pid
Process.detach T.must(pid)
end
end

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/utils/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ def self.safe_fork(&_block)
begin
socket = server.accept_nonblock
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
retry unless Process.waitpid(pid, Process::WNOHANG)
retry unless Process.waitpid(T.must(pid), Process::WNOHANG)
else
socket.send_io(write)
socket.close
end
write.close
data = read.read
read.close
Process.wait(pid) unless socket.nil?
Process.wait(T.must(pid)) unless socket.nil?

# 130 is the exit status for a process interrupted via Ctrl-C.
# We handle it here because of the possibility of an interrupted process terminating
# without writing its Interrupt exception to the error pipe.
raise Interrupt if $CHILD_STATUS.exitstatus == 130

if data && !data.empty?
error_hash = JSON.parse(data.lines.first)
error_hash = JSON.parse(T.must(data.lines.first))

e = ChildProcessError.new(error_hash)

Expand Down

0 comments on commit 6750448

Please sign in to comment.