Merge pull request #9297 from reitermarkus/brew-typecheck

Refactor `brew typecheck` and upgrade `typed` sigils.
This commit is contained in:
Markus Reiter 2020-11-27 00:01:47 +01:00 committed by GitHub
commit 79d6c059fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 100 additions and 57 deletions

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "cask/artifact/moved"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "cask/artifact/moved"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module Cask

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module Cask

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module Cask

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cleanup"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "system_config"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "ostruct"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "migrator"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "sandbox"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "readall"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "ostruct"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
module Language

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "commands"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cache_store"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "bintray"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "json"

View File

@ -22,6 +22,9 @@ module Homebrew
description: "Silence all non-critical errors."
switch "--update",
description: "Update RBI files."
switch "--suggest-typed",
description: "Try upgrading `typed` sigils.",
depends_on: "--update"
switch "--fail-if-not-changed",
description: "Return a failing status code if all gems are up to date " \
"and gem definitions do not need a tapioca update."
@ -38,6 +41,7 @@ module Homebrew
end
end
sig { void }
def typecheck
args = typecheck_args.parse
@ -50,12 +54,44 @@ module Homebrew
system "bundle", "exec", "srb", "rbi", "hidden-definitions"
system "bundle", "exec", "srb", "rbi", "todo"
if args.suggest_typed?
result = system_command(
"bundle",
args: ["exec", "--", "srb", "tc", "--suggest-typed", "--typed=strict", "--error-white-list=7022"],
print_stderr: false,
)
allowed_changes = {
"false" => ["true", "strict"],
"true" => ["strict"],
}
# Workaround for `srb tc rbi suggest-typed`, which currently fails get to a converging state.
result.stderr.scan(/^(.*\.rb):\d+:\s+You could add `#\s*typed:\s*(.*?)`/).each do |path, new_level|
path = Pathname(path)
next unless path.file?
contents = path.read
next unless (match = contents.match(/\A\s*#\s*typed:\s*([^\s]+)/))
existing_level = match[1]
next unless allowed_changes.fetch(existing_level, []).include?(new_level)
puts "#{path}: #{existing_level} -> #{new_level}"
path.atomic_write contents.sub(/\A(\s*#\s*typed:\s*)(?:[^\s]+)/, "\\1#{new_level}")
end
end
Homebrew.failed = system("git", "diff", "--stat", "--exit-code") if args.fail_if_not_changed?
return
end
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?
srb_exec += ["--ignore", args.ignore] if args.ignore.present?

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cli/parser"

View File

@ -1,9 +1,12 @@
# typed: false
# typed: strict
# frozen_string_literal: true
require "requirement"
class XcodeRequirement < Requirement
extend T::Sig
sig { returns(T::Boolean) }
def xcode_installed_version
true
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module SharedEnvExtension

View File

@ -1,4 +1,4 @@
# typed: false
# typed: strict
# frozen_string_literal: true
require "extend/os/linux/requirements/xcode_requirement" if OS.linux?

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
module Homebrew

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
module Language

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "dependable"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
# A requirement on Linux.

View File

@ -20,6 +20,7 @@ class XcodeRequirement < Requirement
super(tags)
end
sig { returns(T::Boolean) }
def xcode_installed_version
return false unless MacOS::Xcode.installed?
return true unless @version

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "download_strategy"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
module Homebrew

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
# Utility method extensions for String.

View File

@ -9,6 +9,3 @@
--dsl-plugins
sorbet/triggers.yml
--error-black-list
5061

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "open3"

View File

@ -1,4 +1,4 @@
# typed: false
# typed: strict
# frozen_string_literal: true
require "cli/parser"

View File

@ -1269,6 +1269,8 @@ Check for typechecking errors using Sorbet.
Silence all non-critical errors.
* `--update`:
Update RBI files.
* `--suggest-typed`:
Try upgrading `typed` sigils.
* `--fail-if-not-changed`:
Return a failing status code if all gems are up to date and gem definitions do not need a tapioca update.
* `--dir`:

View File

@ -1753,6 +1753,10 @@ Silence all non\-critical errors\.
Update RBI files\.
.
.TP
\fB\-\-suggest\-typed\fR
Try upgrading \fBtyped\fR sigils\.
.
.TP
\fB\-\-fail\-if\-not\-changed\fR
Return a failing status code if all gems are up to date and gem definitions do not need a tapioca update\.
.