Skip to content

Commit 2957401

Browse files
authored
Merge pull request #76 from Shopify/add_command_to_count_errors
Add option to count errors if files were bumped to true
2 parents d2b4e9c + c870da0 commit 2957401

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/spoom/cli/bump.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Bump < Thor
2626
desc: "Only change specified list (one file by line)"
2727
option :suggest_bump_command, type: :string,
2828
desc: "Command to suggest if files can be bumped"
29+
option :count_errors, type: :boolean, default: false,
30+
desc: "Count the number of errors if all files were bumped"
2931
sig { params(directory: String).void }
3032
def bump(directory = ".")
3133
in_sorbet_project!
@@ -48,6 +50,11 @@ def bump(directory = ".")
4850
exit(1)
4951
end
5052

53+
if options[:count_errors] && !dry
54+
say_error("`--count-errors` can only be used with `--dry`")
55+
exit(1)
56+
end
57+
5158
say("Checking files...")
5259

5360
directory = File.expand_path(directory)
@@ -100,6 +107,8 @@ def bump(directory = ".")
100107

101108
undo_changes(files_with_errors, from)
102109

110+
say("Found #{errors.length} type checking error#{'s' if errors.length > 1}") if options[:count_errors]
111+
103112
files_changed = files_to_bump - files_with_errors
104113
print_changes(files_changed, command: cmd, from: from, to: to, dry: dry, path: exec_path)
105114
undo_changes(files_to_bump, from) if dry

test/spoom/cli/bump_test.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,48 @@ class A; end
367367
assert_equal("true", Sorbet::Sigils.file_strictness("#{@project.path}/file1.rb"))
368368
assert_equal("false", Sorbet::Sigils.file_strictness("#{@project.path}/vendor/file2.rb"))
369369
end
370+
371+
def test_count_errors_without_dry
372+
@project.write("file1.rb", <<~RB)
373+
# typed: false
374+
class Foo
375+
def foo
376+
end
377+
end
378+
379+
Foo.new.foos
380+
RB
381+
382+
out, err, status = @project.bundle_exec("spoom bump --no-color --count-errors")
383+
assert_empty(out)
384+
assert_equal(<<~OUT, err)
385+
Error: `--count-errors` can only be used with `--dry`
386+
OUT
387+
refute(status)
388+
end
389+
390+
def test_bump_count_errors
391+
@project.write("file1.rb", <<~RB)
392+
# typed: false
393+
class Foo
394+
def foo
395+
end
396+
end
397+
398+
Foo.new.foos
399+
RB
400+
401+
out, err, status = @project.bundle_exec("spoom bump --no-color --count-errors --dry")
402+
assert_empty(err)
403+
assert_equal(<<~OUT, out)
404+
Checking files...
405+
406+
Found 1 type checking error
407+
No file to bump from `false` to `true`
408+
OUT
409+
assert(status)
410+
assert_equal("false", Sorbet::Sigils.file_strictness("#{@project.path}/file1.rb"))
411+
end
370412
end
371413
end
372414
end

0 commit comments

Comments
 (0)