tapioca 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2ebe6488f101318e156ba0025de299975fce0d348f05ae9cd7bd38cf77ffe28
4
- data.tar.gz: 3e22db95ccff12b1915f7f783e5669400cb5381078c49f370565da655459d62b
3
+ metadata.gz: f225f517eb2bb6e6d7aa6910bb42a35280b57ad8223dbd8bc255ce92377c6eb3
4
+ data.tar.gz: f3672f181cbcd71b9c8056c815e77313d75fcb2a78d2be5dbad3d2e51e35de39
5
5
  SHA512:
6
- metadata.gz: cb2d0ac2308cd8c44159a737e92090965dfa0ec616aaf83a6ad4b3cea69348bb12d61ecdce7f527db78d75c129fec19e765845ea475c375a74efcc240e1d2f25
7
- data.tar.gz: d4c98b1c97946544c1032f13e920e77a1a62d61ad00e4f6522bef129690b68d2db07d7c08af74f9f7a245c3a771299534fa4a1cf2d464deaf03821e9180b73f6
6
+ metadata.gz: dcd0b9ebf36c2a467bb2e88cb91b1f0634cb772a3a5cf29f7dd3b716ddc3c4fd2ea4dd84b671df243255cc15651deb157d149578dde07f3f7eb26f0a8814a297
7
+ data.tar.gz: df7355fe19f05210797993286ead0f653a0f5b5f89263f469e8afece16d39026bde0cec1a0b266256ab236f43c27e95bd2912be3a9be74877ca6ca28037e09d7
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tapioca
2
2
 
3
- [![Build Status](https://travis-ci.org/Shopify/tapioca.svg?branch=master)](https://travis-ci.org/Shopify/tapioca)
3
+ ![Build Status](https://github.com/Shopify/tapioca/workflows/CI/badge.svg)
4
4
 
5
5
  Tapioca is a library used to generate RBI (Ruby interface) files for use with [Sorbet](https://sorbet.org). RBI files provide the structure (classes, modules, methods, parameters) of the gem/library to Sorbet to assist with typechecking.
6
6
 
@@ -108,7 +108,7 @@ module Tapioca
108
108
  sig { override.returns(T::Enumerable[Module]) }
109
109
  def gather_constants
110
110
  ::ActiveRecord::Base.descendants.select do |klass|
111
- klass < IdentityCache
111
+ klass < IdentityCache::WithoutPrimaryIndex
112
112
  end
113
113
  end
114
114
 
@@ -92,24 +92,28 @@ module Tapioca
92
92
  method_def = signature.nil? ? method_def : signature.method
93
93
  method_types = parameters_types_from_signature(method_def, signature)
94
94
 
95
- method_def.parameters.each_with_index.map do |(type, name), i|
96
- name ||= :_
97
- name = name.to_s.gsub(/&|\*/, '_') # avoid incorrect names from `delegate`
95
+ method_def.parameters.each_with_index.map do |(type, name), index|
96
+ fallback_arg_name = "_arg#{index}"
97
+
98
+ name ||= fallback_arg_name
99
+ name = name.to_s.gsub(/&|\*/, fallback_arg_name) # avoid incorrect names from `delegate`
100
+ method_type = method_types[index]
101
+
98
102
  case type
99
103
  when :req
100
- ::Parlour::RbiGenerator::Parameter.new(name, type: method_types[i])
104
+ ::Parlour::RbiGenerator::Parameter.new(name, type: method_type)
101
105
  when :opt
102
- ::Parlour::RbiGenerator::Parameter.new(name, type: method_types[i], default: 'T.unsafe(nil)')
106
+ ::Parlour::RbiGenerator::Parameter.new(name, type: method_type, default: 'T.unsafe(nil)')
103
107
  when :rest
104
- ::Parlour::RbiGenerator::Parameter.new("*#{name}", type: method_types[i])
108
+ ::Parlour::RbiGenerator::Parameter.new("*#{name}", type: method_type)
105
109
  when :keyreq
106
- ::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_types[i])
110
+ ::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_type)
107
111
  when :key
108
- ::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_types[i], default: 'T.unsafe(nil)')
112
+ ::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_type, default: 'T.unsafe(nil)')
109
113
  when :keyrest
110
- ::Parlour::RbiGenerator::Parameter.new("**#{name}", type: method_types[i])
114
+ ::Parlour::RbiGenerator::Parameter.new("**#{name}", type: method_type)
111
115
  when :block
112
- ::Parlour::RbiGenerator::Parameter.new("&#{name}", type: method_types[i])
116
+ ::Parlour::RbiGenerator::Parameter.new("&#{name}", type: method_type)
113
117
  else
114
118
  raise "Unknown type `#{type}`."
115
119
  end
@@ -34,7 +34,8 @@ module Tapioca
34
34
  path = (Pathname.new(@sorbet_path) / "../.." / path).cleanpath
35
35
  if path.directory?
36
36
  Dir.glob("#{path}/**/*.rb", File::FNM_EXTGLOB).reject do |file|
37
- file_ignored_by_sorbet?(config, file)
37
+ relative_file_path = Pathname.new(file).relative_path_from(path)
38
+ file_ignored_by_sorbet?(config, relative_file_path)
38
39
  end
39
40
  else
40
41
  [path.to_s]
@@ -49,13 +50,40 @@ module Tapioca
49
50
  end.compact
50
51
  end
51
52
 
52
- sig { params(config: Spoom::Sorbet::Config, file: String).returns(T::Boolean) }
53
- def file_ignored_by_sorbet?(config, file)
54
- config.ignore.any? do |path|
55
- Regexp.new(Regexp.escape(path)) =~ file
53
+ sig { params(config: Spoom::Sorbet::Config, file_path: Pathname).returns(T::Boolean) }
54
+ def file_ignored_by_sorbet?(config, file_path)
55
+ file_path_parts = path_parts(file_path)
56
+
57
+ config.ignore.any? do |ignore|
58
+ # Sorbet --ignore matching method:
59
+ # ---
60
+ # Ignores input files that contain the given
61
+ # string in their paths (relative to the input
62
+ # path passed to Sorbet).
63
+ #
64
+ # Strings beginning with / match against the
65
+ # prefix of these relative paths; others are
66
+ # substring matchs.
67
+
68
+ # Matches must be against whole folder and file
69
+ # names, so `foo` matches `/foo/bar.rb` and
70
+ # `/bar/foo/baz.rb` but not `/foo.rb` or
71
+ # `/foo2/bar.rb`.
72
+ ignore_parts = path_parts(Pathname.new(ignore))
73
+ file_path_part_sequences = file_path_parts.each_cons(ignore_parts.size)
74
+ # if ignore string begins with /, we only want the first sequence to match
75
+ file_path_part_sequences = [file_path_part_sequences.first].to_enum if ignore.start_with?("/")
76
+
77
+ # we need to match whole segments
78
+ file_path_part_sequences.include?(ignore_parts)
56
79
  end
57
80
  end
58
81
 
82
+ sig { params(path: Pathname).returns(T::Array[String]) }
83
+ def path_parts(path)
84
+ T.unsafe(path).descend.map { |part| part.basename.to_s }
85
+ end
86
+
59
87
  sig { params(files: T::Enumerable[String], name: String).returns(T::Boolean) }
60
88
  def name_in_project?(files, name)
61
89
  files.any? do |file|
@@ -209,7 +209,11 @@ module Tapioca
209
209
  method = "const" if prop.fetch(:immutable, false)
210
210
  type = prop.fetch(:type_object, "T.untyped")
211
211
 
212
- indented("#{method} :#{name}, #{type}")
212
+ if prop.key?(:default)
213
+ indented("#{method} :#{name}, #{type}, default: T.unsafe(nil)")
214
+ else
215
+ indented("#{method} :#{name}, #{type}")
216
+ end
213
217
  end.join("\n")
214
218
  end
215
219
 
@@ -513,7 +517,9 @@ module Tapioca
513
517
 
514
518
  parameters = T.let(method.parameters, T::Array[[Symbol, T.nilable(Symbol)]])
515
519
 
516
- sanitized_parameters = parameters.map do |type, name|
520
+ sanitized_parameters = parameters.each_with_index.map do |(type, name), index|
521
+ fallback_arg_name = "_arg#{index}"
522
+
517
523
  unless name
518
524
  # For attr_writer methods, Sorbet signatures have the name
519
525
  # of the method (without the trailing = sign) as the name of
@@ -533,12 +539,12 @@ module Tapioca
533
539
  name = if writer_method_with_sig
534
540
  T.must(method_name[0...-1]).to_sym
535
541
  else
536
- :_
542
+ fallback_arg_name
537
543
  end
538
544
  end
539
545
 
540
546
  # Sanitize param names
541
- name = name.to_s.gsub(/[^a-zA-Z0-9_]/, '_')
547
+ name = name.to_s.gsub(/[^a-zA-Z0-9_]/, fallback_arg_name)
542
548
 
543
549
  [type, name]
544
550
  end
@@ -612,6 +618,7 @@ module Tapioca
612
618
  signature_body = signature_body
613
619
  .gsub(".returns(<VOID>)", ".void")
614
620
  .gsub("<NOT-TYPED>", "T.untyped")
621
+ .gsub(".params()", "")
615
622
  .gsub(TYPE_PARAMETER_MATCHER, "T.type_parameter(:\\1)")[1..-1]
616
623
 
617
624
  "sig { #{signature_body} }"
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.4.7"
5
+ VERSION = "0.4.8"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2020-10-07 00:00:00.000000000 Z
14
+ date: 2020-11-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pry