Skip to content

Commit

Permalink
Auto-update gem RBI strictnesses after DSL generation
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Mar 1, 2022
1 parent 2ab2cb3 commit c8e4611
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/tapioca/commands/dsl.rb
Expand Up @@ -4,6 +4,9 @@
module Tapioca
module Commands
class Dsl < Command
include SorbetHelper
include RBIHelper

sig do
params(
requested_constants: T::Array[String],
Expand All @@ -17,6 +20,8 @@ class Dsl < Command
quiet: T::Boolean,
verbose: T::Boolean,
number_of_workers: T.nilable(Integer),
auto_strictness: T::Boolean,
gem_dir: String,
rbi_formatter: RBIFormatter
).void
end
Expand All @@ -32,6 +37,8 @@ def initialize(
quiet: false,
verbose: false,
number_of_workers: nil,
auto_strictness: true,
gem_dir: DEFAULT_GEM_DIR,
rbi_formatter: DEFAULT_RBI_FORMATTER
)
@requested_constants = requested_constants
Expand All @@ -45,6 +52,8 @@ def initialize(
@quiet = quiet
@verbose = verbose
@number_of_workers = number_of_workers
@auto_strictness = auto_strictness
@gem_dir = gem_dir
@rbi_formatter = rbi_formatter

super()
Expand Down Expand Up @@ -102,9 +111,14 @@ def execute
perform_dsl_verification(outpath)
else
purge_stale_dsl_rbi_files(rbi_files_to_purge)

say("Done", :green)

if @auto_strictness
say("")
update_gem_rbis_strictnesses([], gem_dir: @gem_dir, dsl_dir: @outpath.to_s)
say("")
end

say("All operations performed in working directory.", [:green, :bold])
say("Please review changes and commit them.", [:green, :bold])
end
Expand Down
100 changes: 100 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Expand Up @@ -93,6 +93,10 @@ class Post
create sorbet/rbi/dsl/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -202,6 +206,10 @@ class Comment
create sorbet/rbi/dsl/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -281,6 +289,10 @@ class Role
create sorbet/rbi/dsl/foo/role.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -344,6 +356,10 @@ class Comment
create rbis/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -392,6 +408,10 @@ class Comment
create sorbet/rbi/dsl/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -423,6 +443,10 @@ class Post
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -492,6 +516,10 @@ class Post
remove sorbet/rbi/dsl/to_be_deleted/foo.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -603,6 +631,10 @@ class User; end
remove sorbet/rbi/dsl/user.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -681,6 +713,10 @@ def self.gather_constants
create sorbet/rbi/dsl/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -769,6 +805,10 @@ def self.gather_constants
create sorbet/rbi/dsl/job.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -872,6 +912,10 @@ def self.gather_constants
create sorbet/rbi/dsl/post.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -983,6 +1027,10 @@ class Image
force sorbet/rbi/dsl/image.rbi
Done
Typechecking RBI files... Done
No error found
All operations performed in working directory.
Please review changes and commit them.
OUT
Expand Down Expand Up @@ -1180,6 +1228,58 @@ class Post
refute_success_status(result)
end
end

describe "strictness" do
it "must turn the strictness of gem RBI files with errors to false" do
@project.require_real_gem("smart_properties", "1.15.0")
@project.bundle_install
# @project.tapioca("init")

@project.write("sorbet/rbi/gems/foo@0.0.1.rbi", <<~RBI)
# typed: true
module Post::SmartPropertiesGeneratedMethods
def foo; end
end
RBI

@project.write("sorbet/rbi/gems/bar@1.0.0.rbi", <<~RBI)
# typed: true
module Post::SmartPropertiesGeneratedMethods
sig { params(title: T.nilable(::String), subtitle: T.nilable(::String)).returns(T.nilable(::String)) }
def title=(title, subtitle); end
end
RBI

@project.write("lib/post.rb", <<~RB)
require "smart_properties"
class Post
include SmartProperties
property :title, accepts: String
end
RB

result = @project.tapioca("dsl Post")

assert_includes(result.out, <<~OUT)
Typechecking RBI files... Done
Changed strictness of sorbet/rbi/gems/bar@1.0.0.rbi to `typed: false` (conflicting with DSL files)
OUT

assert_file_strictness("true", "sorbet/rbi/gems/foo@0.0.1.rbi")
assert_file_strictness("false", "sorbet/rbi/gems/bar@1.0.0.rbi")
assert_file_strictness("true", "sorbet/rbi/dsl/post.rbi")

assert_empty_stderr(result)
assert_success_status(result)

@project.remove("sorbet/rbi/gems")
@project.remove("sorbet/rbi/dsl")
end
end
end
end
end

0 comments on commit c8e4611

Please sign in to comment.