From e61787170d44d91501a073e18c9cb03902475b7d Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 14 Jun 2022 17:08:23 -0400 Subject: [PATCH 1/5] Also check the sorbet/rbi/todo.rbi file when running check-shims Signed-off-by: Alexandre Terrasa --- lib/tapioca/cli.rb | 2 + lib/tapioca/commands/check_shims.rb | 11 ++- lib/tapioca/helpers/rbi_files_helper.rb | 64 +++++++----- spec/tapioca/cli/check_shims_spec.rb | 123 ++++++++++++++++++++++-- 4 files changed, 165 insertions(+), 35 deletions(-) diff --git a/lib/tapioca/cli.rb b/lib/tapioca/cli.rb index e7694ce5b..1e0af1e19 100644 --- a/lib/tapioca/cli.rb +++ b/lib/tapioca/cli.rb @@ -258,6 +258,7 @@ def gem(*gems) option :dsl_rbi_dir, type: :string, desc: "Path to DSL RBIs", default: DEFAULT_DSL_DIR option :shim_rbi_dir, type: :string, desc: "Path to shim RBIs", default: DEFAULT_SHIM_DIR option :annotations_rbi_dir, type: :string, desc: "Path to annotations RBIs", default: DEFAULT_ANNOTATIONS_DIR + option :todo_rbi_file, type: :string, desc: "Path to the generated todo RBI file", default: DEFAULT_TODO_FILE option :payload, type: :boolean, desc: "Check shims against Sorbet's payload", default: true def check_shims command = Commands::CheckShims.new( @@ -265,6 +266,7 @@ def check_shims dsl_rbi_dir: options[:dsl_rbi_dir], shim_rbi_dir: options[:shim_rbi_dir], annotations_rbi_dir: options[:annotations_rbi_dir], + todo_rbi_file: options[:todo_rbi_file], payload: options[:payload] ) command.execute diff --git a/lib/tapioca/commands/check_shims.rb b/lib/tapioca/commands/check_shims.rb index 55fca2ee8..716e8b963 100644 --- a/lib/tapioca/commands/check_shims.rb +++ b/lib/tapioca/commands/check_shims.rb @@ -14,15 +14,17 @@ class CheckShims < Command dsl_rbi_dir: String, annotations_rbi_dir: String, shim_rbi_dir: String, + todo_rbi_file: String, payload: T::Boolean ).void end - def initialize(gem_rbi_dir:, dsl_rbi_dir:, annotations_rbi_dir:, shim_rbi_dir:, payload:) + def initialize(gem_rbi_dir:, dsl_rbi_dir:, annotations_rbi_dir:, shim_rbi_dir:, todo_rbi_file:, payload:) super() @gem_rbi_dir = gem_rbi_dir @dsl_rbi_dir = dsl_rbi_dir @annotations_rbi_dir = annotations_rbi_dir @shim_rbi_dir = shim_rbi_dir + @todo_rbi_file = todo_rbi_file @payload = payload end @@ -30,7 +32,7 @@ def initialize(gem_rbi_dir:, dsl_rbi_dir:, annotations_rbi_dir:, shim_rbi_dir:, def execute index = RBI::Index.new - if !Dir.exist?(@shim_rbi_dir) || Dir.empty?(@shim_rbi_dir) + if (!Dir.exist?(@shim_rbi_dir) || Dir.empty?(@shim_rbi_dir)) && !File.exist?(@todo_rbi_file) say("No shim RBIs to check", :green) exit(0) end @@ -59,12 +61,13 @@ def execute end end + index_rbi(index, "todo", @todo_rbi_file) index_rbis(index, "shim", @shim_rbi_dir) index_rbis(index, "gem", @gem_rbi_dir) index_rbis(index, "dsl", @dsl_rbi_dir) index_rbis(index, "annotation", @annotations_rbi_dir) - duplicates = duplicated_nodes_from_index(index, @shim_rbi_dir) + duplicates = duplicated_nodes_from_index(index, shim_rbi_dir: @shim_rbi_dir, todo_rbi_file: @todo_rbi_file) unless duplicates.empty? duplicates.each do |key, nodes| say_error("\nDuplicated RBI for #{key}:", :red) @@ -76,7 +79,7 @@ def execute say_error(" * #{loc_string}", :red) end end - say_error("\nPlease remove the duplicated definitions from the #{@shim_rbi_dir} directory.", :red) + say_error("\nPlease remove the duplicated definitions from the #{@shim_rbi_dir} and #{@todo_rbi_file}.", :red) exit(1) end diff --git a/lib/tapioca/helpers/rbi_files_helper.rb b/lib/tapioca/helpers/rbi_files_helper.rb index 47430920a..d030ac26c 100644 --- a/lib/tapioca/helpers/rbi_files_helper.rb +++ b/lib/tapioca/helpers/rbi_files_helper.rb @@ -19,6 +19,15 @@ def index_payload(index, dir) say(" Done", :green) end + sig { params(index: RBI::Index, kind: String, file: String).void } + def index_rbi(index, kind, file) + return unless File.exist?(file) + + say("Loading #{kind} RBIs from #{file}... ") + parse_and_index_file(index, file) + say(" Done", :green) + end + sig { params(index: RBI::Index, kind: String, dir: String).void } def index_rbis(index, kind, dir) return unless Dir.exist?(dir) && !Dir.empty?(dir) @@ -29,13 +38,19 @@ def index_rbis(index, kind, dir) say(" Done", :green) end - sig { params(index: RBI::Index, shim_rbi_dir: String).returns(T::Hash[String, T::Array[RBI::Node]]) } - def duplicated_nodes_from_index(index, shim_rbi_dir) + sig do + params( + index: RBI::Index, + shim_rbi_dir: String, + todo_rbi_file: String + ).returns(T::Hash[String, T::Array[RBI::Node]]) + end + def duplicated_nodes_from_index(index, shim_rbi_dir:, todo_rbi_file:) duplicates = {} say("Looking for duplicates... ") index.keys.each do |key| nodes = index[key] - next unless shims_have_duplicates?(nodes, shim_rbi_dir) + next unless shims_or_todos_have_duplicates?(nodes, shim_rbi_dir: shim_rbi_dir, todo_rbi_file: todo_rbi_file) duplicates[key] = nodes end @@ -137,31 +152,36 @@ def validate_rbi_files(command:, gem_dir:, dsl_dir:, auto_strictness:, gems: [], sig { params(index: RBI::Index, files: T::Array[String]).void } def parse_and_index_files(index, files) - trees = files.map do |file| - RBI::Parser.parse_file(file) - rescue RBI::ParseError => e - say_error("\nWarning: #{e} (#{e.location})", :yellow) - end.compact - index.visit_all(trees) + files.each do |file| + parse_and_index_file(index, file) + end + end + + sig { params(index: RBI::Index, file: String).void } + def parse_and_index_file(index, file) + tree = RBI::Parser.parse_file(file) + index.visit(tree) + rescue RBI::ParseError => e + say_error("\nWarning: #{e} (#{e.location})", :yellow) end - sig { params(nodes: T::Array[RBI::Node], shim_rbi_dir: String).returns(T::Boolean) } - def shims_have_duplicates?(nodes, shim_rbi_dir) + sig { params(nodes: T::Array[RBI::Node], shim_rbi_dir: String, todo_rbi_file: String).returns(T::Boolean) } + def shims_or_todos_have_duplicates?(nodes, shim_rbi_dir:, todo_rbi_file:) return false if nodes.size == 1 - shims = extract_shims(nodes, shim_rbi_dir) - return false if shims.empty? + shims_or_todos = extract_shims_and_todos(nodes, shim_rbi_dir: shim_rbi_dir, todo_rbi_file: todo_rbi_file) + return false if shims_or_todos.empty? - props = extract_methods_and_attrs(shims) + props = extract_methods_and_attrs(shims_or_todos) return false if props.empty? - shims_with_sigs = extract_nodes_with_sigs(props) - shims_with_sigs.each do |shim| - shim_sigs = shim.sigs + shims_or_todos_with_sigs = extract_nodes_with_sigs(props) + shims_or_todos_with_sigs.each do |shim_or_todo| + shims_or_todos_sigs = shim_or_todo.sigs extract_methods_and_attrs(nodes).each do |node| - next if node == shim - return true if shim_sigs.all? { |sig| node.sigs.include?(sig) } + next if node == shim_or_todo + return true if shims_or_todos_sigs.all? { |sig| node.sigs.include?(sig) } end return false @@ -170,10 +190,10 @@ def shims_have_duplicates?(nodes, shim_rbi_dir) true end - sig { params(nodes: T::Array[RBI::Node], shim_rbi_dir: String).returns(T::Array[RBI::Node]) } - def extract_shims(nodes, shim_rbi_dir) + sig { params(nodes: T::Array[RBI::Node], shim_rbi_dir: String, todo_rbi_file: String).returns(T::Array[RBI::Node]) } + def extract_shims_and_todos(nodes, shim_rbi_dir:, todo_rbi_file:) nodes.select do |node| - node.loc&.file&.start_with?(shim_rbi_dir) + node.loc&.file&.start_with?(shim_rbi_dir) || node.loc&.file == todo_rbi_file end end diff --git a/spec/tapioca/cli/check_shims_spec.rb b/spec/tapioca/cli/check_shims_spec.rb index 270462cc9..b1d4e9f4c 100644 --- a/spec/tapioca/cli/check_shims_spec.rb +++ b/spec/tapioca/cli/check_shims_spec.rb @@ -103,7 +103,7 @@ def bar; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) @@ -182,7 +182,7 @@ def baz(x, y); end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_includes(result.err, "Duplicated RBI for ::Foo#bar") @@ -213,7 +213,7 @@ class Foo ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) @@ -243,7 +243,7 @@ def foo; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) @@ -287,7 +287,7 @@ def self.some_method_that_is_not_defined_in_the_payload; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) @@ -311,10 +311,21 @@ class Foo def foo; end def bar; end end + + module Baz + def baz; end + end + RBI + + @project.write("rbi/todo.rbi", <<~RBI) + module Baz + def baz; end + end RBI result = @project.tapioca( - "check-shims --gem-rbi-dir=rbi/gem --dsl-rbi-dir=rbi/dsl --shim-rbi-dir=rbi/shim --no-payload" + "check-shims --gem-rbi-dir=rbi/gem --dsl-rbi-dir=rbi/dsl --shim-rbi-dir=rbi/shim " \ + "--todo-rbi-file=rbi/todo.rbi --no-payload" ) assert_includes(result.err, <<~ERR) @@ -330,7 +341,13 @@ def bar; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the rbi/shim directory. + Duplicated RBI for ::Baz#baz: + * rbi/todo.rbi:2:2-2:14 + * rbi/shim/foo.rbi:7:2-7:14 + ERR + + assert_includes(result.err, <<~ERR) + Please remove the duplicated definitions from the rbi/shim and rbi/todo.rbi. ERR refute_success_status(result) @@ -368,7 +385,7 @@ def foo; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) @@ -414,7 +431,95 @@ def bar; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims directory. + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + ERR + + refute_success_status(result) + end + + it "detects duplicated definitions between the TODO file and generated RBIs" do + @project.write("sorbet/rbi/gems/foo@1.0.0.rbi", <<~RBI) + class Foo + attr_reader :foo + end + RBI + + @project.write("sorbet/rbi/dsl/bar.rbi", <<~RBI) + module Bar + def bar; end + end + RBI + + @project.write("sorbet/rbi/todo.rbi", <<~RBI) + class Foo + attr_reader :foo + end + + module Bar + def bar; end + end + RBI + + result = @project.tapioca("check-shims --no-payload") + + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Bar#bar: + * sorbet/rbi/todo.rbi:6:2-6:14 + * sorbet/rbi/dsl/bar.rbi:2:2-2:14 + ERR + + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Foo#foo: + * sorbet/rbi/todo.rbi:2:2-2:18 + * sorbet/rbi/gems/foo@1.0.0.rbi:2:2-2:18 + ERR + + assert_includes(result.err, <<~ERR) + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + ERR + + refute_success_status(result) + end + + it "detects duplicated definitions between the TODO file and shims" do + @project.write("sorbet/rbi/shims/foo.rbi", <<~RBI) + class Foo + attr_reader :foo + end + RBI + + @project.write("sorbet/rbi/shims/bar.rbi", <<~RBI) + module Bar + def bar; end + end + RBI + + @project.write("sorbet/rbi/todo.rbi", <<~RBI) + class Foo + attr_reader :foo + end + + module Bar + def bar; end + end + RBI + + result = @project.tapioca("check-shims --no-payload") + + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Bar#bar: + * sorbet/rbi/todo.rbi:6:2-6:14 + * sorbet/rbi/shims/bar.rbi:2:2-2:14 + ERR + + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Foo#foo: + * sorbet/rbi/todo.rbi:2:2-2:18 + * sorbet/rbi/shims/foo.rbi:2:2-2:18 + ERR + + assert_includes(result.err, <<~ERR) + Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR refute_success_status(result) From 4b0df4586770eceb0edf63f581585f98e60131ca Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 14 Jun 2022 18:16:58 -0400 Subject: [PATCH 2/5] Also report errors for useless empty scopes Signed-off-by: Alexandre Terrasa --- lib/tapioca/helpers/rbi_files_helper.rb | 8 +++ spec/tapioca/cli/check_shims_spec.rb | 86 ++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/lib/tapioca/helpers/rbi_files_helper.rb b/lib/tapioca/helpers/rbi_files_helper.rb index d030ac26c..81708eebb 100644 --- a/lib/tapioca/helpers/rbi_files_helper.rb +++ b/lib/tapioca/helpers/rbi_files_helper.rb @@ -172,6 +172,9 @@ def shims_or_todos_have_duplicates?(nodes, shim_rbi_dir:, todo_rbi_file:) shims_or_todos = extract_shims_and_todos(nodes, shim_rbi_dir: shim_rbi_dir, todo_rbi_file: todo_rbi_file) return false if shims_or_todos.empty? + shims_or_todos_empty_scopes = extract_empty_scopes(shims_or_todos) + return true unless shims_or_todos_empty_scopes.empty? + props = extract_methods_and_attrs(shims_or_todos) return false if props.empty? @@ -197,6 +200,11 @@ def extract_shims_and_todos(nodes, shim_rbi_dir:, todo_rbi_file:) end end + sig { params(nodes: T::Array[RBI::Node]).returns(T::Array[RBI::Scope]) } + def extract_empty_scopes(nodes) + T.cast(nodes.select { |node| node.is_a?(RBI::Scope) && node.empty? }, T::Array[RBI::Scope]) + end + sig { params(nodes: T::Array[RBI::Node]).returns(T::Array[T.any(RBI::Method, RBI::Attr)]) } def extract_methods_and_attrs(nodes) T.cast(nodes.select do |node| diff --git a/spec/tapioca/cli/check_shims_spec.rb b/spec/tapioca/cli/check_shims_spec.rb index b1d4e9f4c..31804576d 100644 --- a/spec/tapioca/cli/check_shims_spec.rb +++ b/spec/tapioca/cli/check_shims_spec.rb @@ -41,12 +41,18 @@ class Foo @project.write("sorbet/rbi/gems/foo@1.0.0.rbi", <<~RBI) class Foo attr_reader :foo + + class Baz; end end RBI @project.write("sorbet/rbi/shims/foo.rbi", <<~RBI) class Foo attr_reader :bar + + class Baz + def baz; end + end end RBI @@ -76,6 +82,10 @@ def bar; end end RBI + @project.write("sorbet/rbi/dsl/baz.rbi", <<~RBI) + module Baz; end + RBI + @project.write("sorbet/rbi/shims/foo.rbi", <<~RBI) class Foo attr_reader :foo @@ -88,6 +98,12 @@ def bar; end end RBI + @project.write("sorbet/rbi/shims/baz.rbi", <<~RBI) + module Baz + def baz; end + end + RBI + result = @project.tapioca("check-shims --no-payload") assert_includes(result.err, <<~ERR) @@ -223,14 +239,23 @@ class Foo @project.write("sorbet/rbi/gems/foo@1.0.0.rbi", <<~RBI) class Foo attr_reader :foo + + class Baz; end end + + class Bar; end RBI @project.write("sorbet/rbi/shims/foo.rbi", <<~RBI) class Foo attr_reader :foo, :bar def foo; end + + class Baz; end end + + class Bar; end + class Bar; end RBI result = @project.tapioca("check-shims --no-payload") @@ -242,6 +267,19 @@ def foo; end * sorbet/rbi/gems/foo@1.0.0.rbi:2:2-2:18 ERR + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Foo::Baz: + * sorbet/rbi/shims/foo.rbi:5:2-5:16 + * sorbet/rbi/gems/foo@1.0.0.rbi:4:2-4:16 + ERR + + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Bar: + * sorbet/rbi/shims/foo.rbi:8:0-8:14 + * sorbet/rbi/shims/foo.rbi:9:0-9:14 + * sorbet/rbi/gems/foo@1.0.0.rbi:7:0-7:14 + ERR + assert_includes(result.err, <<~ERR) Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR @@ -250,6 +288,10 @@ def foo; end end it "detects duplicates from Sorbet's payload" do + @project.write("sorbet/rbi/shims/core/object.rbi", <<~RBI) + class Object; end + RBI + @project.write("sorbet/rbi/shims/core/string.rbi", <<~RBI) class String sig { returns(String) } @@ -276,6 +318,12 @@ def self.some_method_that_is_not_defined_in_the_payload; end Looking for duplicates... Done OUT + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Object: + * https://github.com/sorbet/sorbet/tree/master/rbi/core/object.rbi#L27 + * sorbet/rbi/shims/core/object.rbi:1:0-1:17 + ERR + assert_includes(result.err, <<~ERR) Duplicated RBI for ::String#capitalize: * https://github.com/sorbet/sorbet/tree/master/rbi/core/string.rbi#L406 @@ -404,6 +452,10 @@ def bar; end end RBI + @project.write("sorbet/rbi/annotations/baz.rbi", <<~RBI) + module Baz; end + RBI + @project.write("sorbet/rbi/shims/foo.rbi", <<~RBI) class Foo attr_reader :foo @@ -416,6 +468,10 @@ def bar; end end RBI + @project.write("sorbet/rbi/shims/baz.rbi", <<~RBI) + module Baz; end + RBI + result = @project.tapioca("check-shims --no-payload") assert_includes(result.err, <<~ERR) @@ -430,6 +486,12 @@ def bar; end * sorbet/rbi/annotations/foo.rbi:2:2-2:18 ERR + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Baz: + * sorbet/rbi/shims/baz.rbi:1:0-1:15 + * sorbet/rbi/annotations/baz.rbi:1:0-1:15 + ERR + assert_includes(result.err, <<~ERR) Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR @@ -441,6 +503,8 @@ def bar; end @project.write("sorbet/rbi/gems/foo@1.0.0.rbi", <<~RBI) class Foo attr_reader :foo + + class Baz; end end RBI @@ -453,6 +517,8 @@ def bar; end @project.write("sorbet/rbi/todo.rbi", <<~RBI) class Foo attr_reader :foo + + class Baz; end end module Bar @@ -464,7 +530,7 @@ def bar; end assert_includes(result.err, <<~ERR) Duplicated RBI for ::Bar#bar: - * sorbet/rbi/todo.rbi:6:2-6:14 + * sorbet/rbi/todo.rbi:8:2-8:14 * sorbet/rbi/dsl/bar.rbi:2:2-2:14 ERR @@ -474,6 +540,12 @@ def bar; end * sorbet/rbi/gems/foo@1.0.0.rbi:2:2-2:18 ERR + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Foo::Baz: + * sorbet/rbi/todo.rbi:4:2-4:16 + * sorbet/rbi/gems/foo@1.0.0.rbi:4:2-4:16 + ERR + assert_includes(result.err, <<~ERR) Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR @@ -494,6 +566,10 @@ def bar; end end RBI + @project.write("sorbet/rbi/shims/baz.rbi", <<~RBI) + module Baz; end + RBI + @project.write("sorbet/rbi/todo.rbi", <<~RBI) class Foo attr_reader :foo @@ -502,6 +578,8 @@ class Foo module Bar def bar; end end + + module Baz; end RBI result = @project.tapioca("check-shims --no-payload") @@ -518,6 +596,12 @@ def bar; end * sorbet/rbi/shims/foo.rbi:2:2-2:18 ERR + assert_includes(result.err, <<~ERR) + Duplicated RBI for ::Baz: + * sorbet/rbi/todo.rbi:9:0-9:15 + * sorbet/rbi/shims/baz.rbi:1:0-1:15 + ERR + assert_includes(result.err, <<~ERR) Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. ERR From 2e5fc8ce1a2c703d4676e2eb7df1b1060963a297 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 14 Jun 2022 18:26:07 -0400 Subject: [PATCH 3/5] Remove useless shims Signed-off-by: Alexandre Terrasa --- sorbet/rbi/shims/error_highlight.rbi | 3 --- sorbet/rbi/shims/rdoc.rbi | 1 - 2 files changed, 4 deletions(-) delete mode 100644 sorbet/rbi/shims/error_highlight.rbi diff --git a/sorbet/rbi/shims/error_highlight.rbi b/sorbet/rbi/shims/error_highlight.rbi deleted file mode 100644 index 412db61c1..000000000 --- a/sorbet/rbi/shims/error_highlight.rbi +++ /dev/null @@ -1,3 +0,0 @@ -# typed: true - -module ErrorHighlight::CoreExt; end diff --git a/sorbet/rbi/shims/rdoc.rbi b/sorbet/rbi/shims/rdoc.rbi index 3cf45fa63..043a4e6a2 100644 --- a/sorbet/rbi/shims/rdoc.rbi +++ b/sorbet/rbi/shims/rdoc.rbi @@ -1,4 +1,3 @@ # typed: true -module RDoc; end class RDoc::Task; end From aefd8ebbad09fc240f7d417f9d607c38afd8b7b1 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 14 Jun 2022 18:28:55 -0400 Subject: [PATCH 4/5] Update README Signed-off-by: Alexandre Terrasa --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e9ab7752e..67f9da993 100644 --- a/README.md +++ b/README.md @@ -717,6 +717,8 @@ Options: # Default: sorbet/rbi/shims [--annotations-rbi-dir=ANNOTATIONS_RBI_DIR] # Path to annotations RBIs # Default: sorbet/rbi/annotations + [--todo-rbi-file=TODO_RBI_FILE] # Path to the generated todo RBI file + # Default: sorbet/rbi/todo.rbi [--payload], [--no-payload] # Check shims against Sorbet's payload # Default: true -c, [--config=] # Path to the Tapioca configuration file @@ -792,6 +794,7 @@ check_shims: dsl_rbi_dir: sorbet/rbi/dsl shim_rbi_dir: sorbet/rbi/shims annotations_rbi_dir: sorbet/rbi/annotations + todo_rbi_file: sorbet/rbi/todo.rbi payload: true annotations: sources: From 686fc5965663276798532fad8a377401c94cc32a Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 16 Jun 2022 15:33:20 -0400 Subject: [PATCH 5/5] Display a better error message for duplciated shims Signed-off-by: Alexandre Terrasa --- lib/tapioca/commands/check_shims.rb | 2 +- spec/tapioca/cli/check_shims_spec.rb | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/tapioca/commands/check_shims.rb b/lib/tapioca/commands/check_shims.rb index 716e8b963..a4302f238 100644 --- a/lib/tapioca/commands/check_shims.rb +++ b/lib/tapioca/commands/check_shims.rb @@ -79,7 +79,7 @@ def execute say_error(" * #{loc_string}", :red) end end - say_error("\nPlease remove the duplicated definitions from the #{@shim_rbi_dir} and #{@todo_rbi_file}.", :red) + say_error("\nPlease remove the duplicated definitions from #{@shim_rbi_dir} and #{@todo_rbi_file}", :red) exit(1) end diff --git a/spec/tapioca/cli/check_shims_spec.rb b/spec/tapioca/cli/check_shims_spec.rb index 31804576d..c61e7239b 100644 --- a/spec/tapioca/cli/check_shims_spec.rb +++ b/spec/tapioca/cli/check_shims_spec.rb @@ -119,7 +119,7 @@ def baz; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -198,7 +198,7 @@ def baz(x, y); end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_includes(result.err, "Duplicated RBI for ::Foo#bar") @@ -229,13 +229,13 @@ class Foo ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) end - it "detects duplicates from the same shim file" do + it "detects duplicates from same shim file" do @project.write("sorbet/rbi/gems/foo@1.0.0.rbi", <<~RBI) class Foo attr_reader :foo @@ -281,7 +281,7 @@ class Bar; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -335,7 +335,7 @@ def self.some_method_that_is_not_defined_in_the_payload; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -395,7 +395,7 @@ def baz; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the rbi/shim and rbi/todo.rbi. + Please remove the duplicated definitions from rbi/shim and rbi/todo.rbi ERR refute_success_status(result) @@ -433,7 +433,7 @@ def foo; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -493,7 +493,7 @@ module Baz; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -547,7 +547,7 @@ def bar; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result) @@ -603,7 +603,7 @@ module Baz; end ERR assert_includes(result.err, <<~ERR) - Please remove the duplicated definitions from the sorbet/rbi/shims and sorbet/rbi/todo.rbi. + Please remove the duplicated definitions from sorbet/rbi/shims and sorbet/rbi/todo.rbi ERR refute_success_status(result)