-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dafa009
commit 737f8cd
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace :steep do | ||
desc "Runs the Steep type checker on the codebase" | ||
task :check do |_task, args| | ||
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7.0") | ||
warn "Sorry, cannot run Steep type checker on older rubies :(" | ||
else | ||
args_sh = args.to_a.map { |a| "'#{a}'" }.join(" ") | ||
|
||
begin | ||
sh "steep check #{args_sh}".strip | ||
rescue | ||
warn <<-EOS | ||
+------------------------------------------------------------------------------+ | ||
| **Hello there, fellow contributor who just triggered a Steep type error** | | ||
| | | ||
| We're still experimenting with Steep on this codebase. If possible, take a | | ||
| stab at getting it to work; you'll find a guide for how to use it here: | | ||
| | | ||
| less docs/StaticTypingGuide.md | | ||
| | | ||
| Feel free to unblock yourself by adding a line per file that triggered | | ||
| errors to the `Steepfile`: | | ||
| | | ||
| ignore 'lib/path/to/failing/file.rb' | | ||
| | | ||
| Also, if this is too annoying for you -- let us know! We definitely are | | ||
| still improving how we use the tool. | | ||
+------------------------------------------------------------------------------+ | ||
EOS | ||
exit 1 | ||
end | ||
end | ||
end | ||
|
||
task :stats do |_task, args| | ||
format = args.to_a.first || "table" | ||
|
||
if format == "md" | ||
data = `steep stats --format=csv` | ||
|
||
require "csv" | ||
|
||
csv = CSV.new(data, headers: true) | ||
headers = true | ||
csv.each do |row| | ||
hrow = row.to_h | ||
|
||
if headers | ||
$stdout.write("|") | ||
$stdout.write(hrow.keys.join("|")) | ||
$stdout.write("|") | ||
$stdout.write("\n") | ||
|
||
$stdout.write("|") | ||
$stdout.write(hrow.values.map { |v| /^\d+$/.match?(v) ? "--:" : ":--" }.join("|")) | ||
$stdout.write("|") | ||
$stdout.write("\n") | ||
end | ||
|
||
headers = false | ||
|
||
$stdout.write("|") | ||
$stdout.write(hrow.values.join("|")) | ||
$stdout.write("|") | ||
$stdout.write("\n") | ||
end | ||
else | ||
sh "steep stats --format=#{format}" | ||
end | ||
end | ||
end | ||
|
||
task typecheck: :"steep:check" |