Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/spoom/cli/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Bump < Thor
desc: "Only change specified list (one file by line)"
option :suggest_bump_command, type: :string,
desc: "Command to suggest if files can be bumped"
option :count_errors, type: :boolean, default: false,
desc: "Count the number of errors if all files were bumped"
sig { params(directory: String).void }
def bump(directory = ".")
in_sorbet_project!
Expand All @@ -48,6 +50,11 @@ def bump(directory = ".")
exit(1)
end

if options[:count_errors] && !dry
say_error("`--count-errors` can only be used with `--dry`")
exit(1)
end

say("Checking files...")

directory = File.expand_path(directory)
Expand Down Expand Up @@ -95,6 +102,8 @@ def bump(directory = ".")

undo_changes(files_with_errors, from)

say("Found #{errors.length} type checking error#{'s' if errors.length > 1}") if options[:count_errors]

files_changed = files_to_bump - files_with_errors
print_changes(files_changed, command: cmd, from: from, to: to, dry: dry, path: exec_path)
undo_changes(files_to_bump, from) if dry
Expand Down
42 changes: 42 additions & 0 deletions test/spoom/cli/bump_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,48 @@ class A; end
assert_equal("true", Sorbet::Sigils.file_strictness("#{@project.path}/file1.rb"))
assert_equal("false", Sorbet::Sigils.file_strictness("#{@project.path}/vendor/file2.rb"))
end

def test_count_errors_without_dry
@project.write("file1.rb", <<~RB)
# typed: false
class Foo
def foo
end
end

Foo.new.foos
RB

out, err, status = @project.bundle_exec("spoom bump --no-color --count-errors")
assert_empty(out)
assert_equal(<<~OUT, err)
Error: `--count-errors` can only be used with `--dry`
OUT
refute(status)
end

def test_bump_count_errors
@project.write("file1.rb", <<~RB)
# typed: false
class Foo
def foo
end
end

Foo.new.foos
RB

out, err, status = @project.bundle_exec("spoom bump --no-color --count-errors --dry")
assert_empty(err)
assert_equal(<<~OUT, out)
Checking files...

Found 1 type checking error
No file to bump from `false` to `true`
OUT
assert(status)
assert_equal("false", Sorbet::Sigils.file_strictness("#{@project.path}/file1.rb"))
end
end
end
end