From c8e461112437ce5531e9d8dba132746fa6485474 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 1 Mar 2022 11:52:25 -0500 Subject: [PATCH] Auto-update gem RBI strictnesses after DSL generation Signed-off-by: Alexandre Terrasa --- lib/tapioca/commands/dsl.rb | 16 +++++- spec/tapioca/cli/dsl_spec.rb | 100 +++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/lib/tapioca/commands/dsl.rb b/lib/tapioca/commands/dsl.rb index 114c9a63c..e0bafa813 100644 --- a/lib/tapioca/commands/dsl.rb +++ b/lib/tapioca/commands/dsl.rb @@ -4,6 +4,9 @@ module Tapioca module Commands class Dsl < Command + include SorbetHelper + include RBIHelper + sig do params( requested_constants: T::Array[String], @@ -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 @@ -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 @@ -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() @@ -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 diff --git a/spec/tapioca/cli/dsl_spec.rb b/spec/tapioca/cli/dsl_spec.rb index 9926d3a4e..3ca4a74f6 100644 --- a/spec/tapioca/cli/dsl_spec.rb +++ b/spec/tapioca/cli/dsl_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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