dev-cmd: add brew typecheck cmd
This PR adds a new `brew typecheck` developer command which checks for typechecking errors in the current code with Sorbet.
This commit is contained in:
parent
9396ccf974
commit
2468fb127d
62
Library/Homebrew/dev-cmd/typecheck.rb
Normal file
62
Library/Homebrew/dev-cmd/typecheck.rb
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cli/parser"
|
||||||
|
|
||||||
|
module Homebrew
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def typecheck_args
|
||||||
|
Homebrew::CLI::Parser.new do
|
||||||
|
usage_banner <<~EOS
|
||||||
|
`typecheck`
|
||||||
|
|
||||||
|
Check for typechecking errors using Sorbet.
|
||||||
|
EOS
|
||||||
|
switch "-q", "--quiet",
|
||||||
|
description: "Silence all non-critical errors."
|
||||||
|
switch "--update-definitions",
|
||||||
|
description: "Update Tapioca gem definitions of recently bumped gems"
|
||||||
|
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"
|
||||||
|
flag "--dir=",
|
||||||
|
description: "Typecheck all files in a specific directory."
|
||||||
|
flag "--file=",
|
||||||
|
description: "Typecheck a single file."
|
||||||
|
flag "--ignore=",
|
||||||
|
description: "Ignores input files that contain the given string " \
|
||||||
|
"in their paths (relative to the input path passed to Sorbet)."
|
||||||
|
conflicts "--dir", "--file"
|
||||||
|
max_named 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def typecheck
|
||||||
|
args = typecheck_args.parse
|
||||||
|
|
||||||
|
Homebrew.install_bundler_gems!
|
||||||
|
|
||||||
|
HOMEBREW_LIBRARY_PATH.cd do
|
||||||
|
if args.update_definitions?
|
||||||
|
system "bundle", "exec", "tapioca", "sync"
|
||||||
|
system "bundle", "exec", "srb", "rbi", "hidden-definitions"
|
||||||
|
|
||||||
|
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 << "--quiet" if args.quiet?
|
||||||
|
srb_exec += ["--ignore", args.ignore] if args.ignore.present?
|
||||||
|
if args.file.present? || args.dir.present?
|
||||||
|
cd("sorbet")
|
||||||
|
srb_exec += ["--file", "../#{args.file}"] if args.file
|
||||||
|
srb_exec += ["--dir", "../#{args.dir}"] if args.dir
|
||||||
|
else
|
||||||
|
srb_exec += ["--typed-override", "sorbet/files.yaml"]
|
||||||
|
end
|
||||||
|
Homebrew.failed = !system(*srb_exec)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
7
Library/Homebrew/test/dev-cmd/typecheck_spec.rb
Normal file
7
Library/Homebrew/test/dev-cmd/typecheck_spec.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
|
describe "Homebrew.typecheck_args" do
|
||||||
|
it_behaves_like "parseable arguments"
|
||||||
|
end
|
||||||
@ -81,6 +81,7 @@ tap-info
|
|||||||
tap-new
|
tap-new
|
||||||
test
|
test
|
||||||
tests
|
tests
|
||||||
|
typecheck
|
||||||
uninstal
|
uninstal
|
||||||
uninstall
|
uninstall
|
||||||
unlink
|
unlink
|
||||||
|
|||||||
@ -1178,6 +1178,23 @@ Run Homebrew's unit and integration tests.
|
|||||||
* `--seed`:
|
* `--seed`:
|
||||||
Randomise tests with the specified *`value`* instead of a random seed.
|
Randomise tests with the specified *`value`* instead of a random seed.
|
||||||
|
|
||||||
|
### `typecheck`
|
||||||
|
|
||||||
|
Check for typechecking errors using Sorbet.
|
||||||
|
|
||||||
|
* `-q`, `--quiet`:
|
||||||
|
Silence all non-critical errors.
|
||||||
|
* `--update-definitions`:
|
||||||
|
Update Tapioca gem definitions of recently bumped gems
|
||||||
|
* `--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`:
|
||||||
|
Typecheck all files in a specific directory.
|
||||||
|
* `--file`:
|
||||||
|
Typecheck a single file.
|
||||||
|
* `--ignore`:
|
||||||
|
Ignores input files that contain the given string in their paths (relative to the input path passed to Sorbet).
|
||||||
|
|
||||||
### `unpack` [*`options`*] *`formula`*
|
### `unpack` [*`options`*] *`formula`*
|
||||||
|
|
||||||
Unpack the source files for *`formula`* into subdirectories of the current
|
Unpack the source files for *`formula`* into subdirectories of the current
|
||||||
|
|||||||
@ -1610,6 +1610,33 @@ Run only \fItest_script\fR\fB_spec\.rb\fR\. Appending \fB:\fR\fIline_number\fR w
|
|||||||
\fB\-\-seed\fR
|
\fB\-\-seed\fR
|
||||||
Randomise tests with the specified \fIvalue\fR instead of a random seed\.
|
Randomise tests with the specified \fIvalue\fR instead of a random seed\.
|
||||||
.
|
.
|
||||||
|
.SS "\fBtypecheck\fR"
|
||||||
|
Check for typechecking errors using Sorbet\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-q\fR, \fB\-\-quiet\fR
|
||||||
|
Silence all non\-critical errors\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-update\-definitions\fR
|
||||||
|
Update Tapioca gem definitions of recently bumped gems
|
||||||
|
.
|
||||||
|
.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
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-dir\fR
|
||||||
|
Typecheck all files in a specific directory\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-file\fR
|
||||||
|
Typecheck a single file\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-ignore\fR
|
||||||
|
Ignores input files that contain the given string in their paths (relative to the input path passed to Sorbet)\.
|
||||||
|
.
|
||||||
.SS "\fBunpack\fR [\fIoptions\fR] \fIformula\fR"
|
.SS "\fBunpack\fR [\fIoptions\fR] \fIformula\fR"
|
||||||
Unpack the source files for \fIformula\fR into subdirectories of the current working directory\.
|
Unpack the source files for \fIformula\fR into subdirectories of the current working directory\.
|
||||||
.
|
.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user