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 94b928211c1bf..41dce0eb2b609 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -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) diff --git a/Library/Homebrew/cask/cmd/doctor.rb b/Library/Homebrew/cask/cmd/doctor.rb index c2565191ad8af..d0d5cb0ba1b79 100644 --- a/Library/Homebrew/cask/cmd/doctor.rb +++ b/Library/Homebrew/cask/cmd/doctor.rb @@ -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| diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index a7eec71143851..0181ad0f3ac28 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 7bb127367f2e7..0645087e47015 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -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 @@ -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" diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb index b544af5c100e0..88e7f8321b13c 100644 --- a/Library/Homebrew/dev-cmd/typecheck.rb +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -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") diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 688a743bbf5c2..778a41ea4e708 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -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? diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index cb044513ea950..949b0a86b99b4 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -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] diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index 575a27eeddb25..1c6d5df21de94 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -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) diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 5075767249b70..47d493d8489e3 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -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) @@ -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}" @@ -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 @@ -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 diff --git a/Library/Homebrew/rubocops/deprecate_disable.rb b/Library/Homebrew/rubocops/deprecate_disable.rb index a073092ef1596..2c8cc4b7db34a 100644 --- a/Library/Homebrew/rubocops/deprecate_disable.rb +++ b/Library/Homebrew/rubocops/deprecate_disable.rb @@ -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? diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 82cc34e6926d3..9e01cf13a7289 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -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) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index a66263ac4e309..02eb03a879422 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -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 @@ -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 @@ -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) @@ -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? diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 89dda53098a87..fa1b6cc2b5133 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -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 diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index f7c16566c0d9d..6b858996b6abf 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -64,7 +64,7 @@ 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 @@ -72,7 +72,7 @@ def self.safe_fork(&_block) 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 @@ def self.safe_fork(&_block) 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)