From 6750448d9556dff88e795cbcbc11fa31827df557 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 23 Nov 2020 18:15:48 +0100 Subject: [PATCH] Fix some auto-correctable type errors. --- Library/Homebrew/build.rb | 2 +- Library/Homebrew/cask/cmd/doctor.rb | 2 +- Library/Homebrew/cmd/--env.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 6 ++--- Library/Homebrew/dev-cmd/typecheck.rb | 9 +++++++- Library/Homebrew/migrator.rb | 2 +- Library/Homebrew/missing_formula.rb | 2 +- Library/Homebrew/postinstall.rb | 2 +- Library/Homebrew/readall.rb | 8 +++---- .../Homebrew/rubocops/deprecate_disable.rb | 2 +- Library/Homebrew/test.rb | 2 +- Library/Homebrew/utils.rb | 23 +++++++++++-------- Library/Homebrew/utils/analytics.rb | 2 +- Library/Homebrew/utils/fork.rb | 6 ++--- 14 files changed, 40 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 94b928211c..41dce0eb2b 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -213,7 +213,7 @@ begin 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) diff --git a/Library/Homebrew/cask/cmd/doctor.rb b/Library/Homebrew/cask/cmd/doctor.rb index c2565191ad..d0d5cb0ba1 100644 --- a/Library/Homebrew/cask/cmd/doctor.rb +++ b/Library/Homebrew/cask/cmd/doctor.rb @@ -23,7 +23,7 @@ module Cask 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| diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index a7eec71143..0181ad0f3a 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -51,7 +51,7 @@ module Homebrew 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 diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 7bb127367f..0645087e47 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -261,8 +261,8 @@ module Homebrew 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 @@ -472,7 +472,7 @@ module Homebrew 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" diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index b544af5c10..88e7f8321b 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -93,7 +93,14 @@ module Homebrew 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") diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 688a743bbf..778a41ea4e 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -234,7 +234,7 @@ class Migrator 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? diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index cb044513ea..949b0a86b9 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -94,7 +94,7 @@ module Homebrew 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] diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index 575a27eedd..1c6d5df21d 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -12,7 +12,7 @@ require "cmd/postinstall" 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) diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 5075767249..47d493d848 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -10,7 +10,7 @@ require "cask/cask_loader" 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) @@ -21,7 +21,7 @@ module Readall 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}" @@ -40,7 +40,7 @@ module Readall end def valid_formulae?(formulae) - success = true + success = T.let(true, T::Boolean) formulae.each do |file| Formulary.factory(file) rescue Interrupt @@ -54,7 +54,7 @@ module Readall end def valid_casks?(casks) - success = true + success = T.let(true, T::Boolean) casks.each do |file| Cask::CaskLoader.load(file) rescue Interrupt diff --git a/Library/Homebrew/rubocops/deprecate_disable.rb b/Library/Homebrew/rubocops/deprecate_disable.rb index a073092ef1..2c8cc4b7db 100644 --- a/Library/Homebrew/rubocops/deprecate_disable.rb +++ b/Library/Homebrew/rubocops/deprecate_disable.rb @@ -46,7 +46,7 @@ module RuboCop 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? diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 82cc34e692..9e01cf13a7 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -20,7 +20,7 @@ begin 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) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index a66263ac4e..02eb03a879 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -34,7 +34,7 @@ module Homebrew end exit! 1 # never gets here unless exec failed end - Process.wait(pid) + Process.wait(T.must(pid)) $CHILD_STATUS.success? end @@ -58,10 +58,13 @@ module Homebrew 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 @@ -190,7 +193,7 @@ module Kernel 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) @@ -263,12 +266,12 @@ module Kernel 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? diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 89dda53098..fa1b6cc2b5 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -58,7 +58,7 @@ module Utils "--silent", "--output", "/dev/null", "https://www.google-analytics.com/collect" end - Process.detach pid + Process.detach T.must(pid) end end diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index f7c16566c0..6b858996b6 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -64,7 +64,7 @@ module Utils 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 @@ -72,7 +72,7 @@ module Utils 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 @@ -80,7 +80,7 @@ module Utils 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)