sord 0.9.0 → 3.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  3. data/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
  4. data/.gitignore +0 -0
  5. data/.parlour +6 -2
  6. data/.rspec +0 -0
  7. data/.travis.yml +0 -0
  8. data/CHANGELOG.md +58 -0
  9. data/CODE_OF_CONDUCT.md +0 -0
  10. data/Gemfile +0 -0
  11. data/LICENSE.txt +0 -0
  12. data/README.md +76 -43
  13. data/Rakefile +26 -7
  14. data/exe/sord +48 -6
  15. data/lib/sord.rb +1 -1
  16. data/lib/sord/generator.rb +592 -0
  17. data/lib/sord/logging.rb +0 -0
  18. data/lib/sord/parlour_plugin.rb +24 -3
  19. data/lib/sord/resolver.rb +0 -0
  20. data/lib/sord/type_converter.rb +71 -63
  21. data/lib/sord/version.rb +1 -1
  22. data/rbi/sord.rbi +210 -30
  23. data/sord.gemspec +3 -3
  24. metadata +15 -34
  25. data/lib/sord/rbi_generator.rb +0 -300
  26. data/sorbet/config +0 -0
  27. data/sorbet/rbi/gems/docile.rbi +0 -31
  28. data/sorbet/rbi/gems/parlour.rbi +0 -214
  29. data/sorbet/rbi/gems/rainbow.rbi +0 -117
  30. data/sorbet/rbi/gems/rake.rbi +0 -643
  31. data/sorbet/rbi/gems/rspec-core.rbi +0 -1658
  32. data/sorbet/rbi/gems/rspec-expectations.rbi +0 -389
  33. data/sorbet/rbi/gems/rspec-mocks.rbi +0 -823
  34. data/sorbet/rbi/gems/rspec-support.rbi +0 -268
  35. data/sorbet/rbi/gems/rspec.rbi +0 -14
  36. data/sorbet/rbi/gems/simplecov-html.rbi +0 -30
  37. data/sorbet/rbi/gems/simplecov.rbi +0 -225
  38. data/sorbet/rbi/gems/sorbet-runtime.rbi +0 -670
  39. data/sorbet/rbi/gems/yard.rbi +0 -310
  40. data/sorbet/rbi/hidden-definitions/errors.txt +0 -9285
  41. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -26604
  42. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8575
  43. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  44. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
File without changes
@@ -10,7 +10,7 @@ module Sord
10
10
  @parlour = nil
11
11
  @options = options
12
12
 
13
- options[:comments] = true if options[:comments].nil?
13
+ options[:sord_comments] = true if options[:sord_comments].nil?
14
14
  options[:regenerate] = true if options[:regenerate].nil?
15
15
  options[:replace_errors_with_untyped] ||= false
16
16
  options[:replace_unresolved_with_untyped] ||= false
@@ -37,11 +37,21 @@ module Sord
37
37
  end
38
38
  Sord::Logging.enabled_types = Sord::Logging::AVAILABLE_TYPES - blacklist
39
39
  end
40
+
41
+ if !(options[:rbi] || options[:rbs])
42
+ Sord::Logging.error('No output format given; please specify --rbi or --rbs')
43
+ exit 1
44
+ end
45
+
46
+ if (options[:rbi] && options[:rbs])
47
+ Sord::Logging.error('You cannot specify both --rbi and --rbs; please use only one')
48
+ exit 1
49
+ end
40
50
 
41
51
  if options[:regenerate]
42
52
  begin
43
53
  Sord::Logging.info('Running YARD...')
44
- Bundler.with_clean_env do
54
+ Sord::ParlourPlugin.with_clean_env do
45
55
  system('bundle exec yard')
46
56
  end
47
57
  rescue Errno::ENOENT
@@ -52,12 +62,23 @@ module Sord
52
62
  end
53
63
  end
54
64
 
65
+ options[:mode] = \
66
+ if options[:rbi] then :rbi elsif options[:rbs] then :rbs end
55
67
  options[:parlour] = @parlour
56
68
  options[:root] = root
57
69
 
58
- Sord::RbiGenerator.new(options).run
70
+ Sord::Generator.new(options).run
59
71
 
60
72
  true
61
73
  end
74
+
75
+ def self.with_clean_env &block
76
+ meth = if Bundler.respond_to?(:with_unbundled_env)
77
+ :with_unbundled_env
78
+ else
79
+ :with_clean_env
80
+ end
81
+ Bundler.send meth, &block
82
+ end
62
83
  end
63
84
  end
File without changes
@@ -2,11 +2,12 @@
2
2
  require 'yaml'
3
3
  require 'sord/logging'
4
4
  require 'sord/resolver'
5
+ require 'parlour'
5
6
 
6
7
  module Sord
7
- # Contains methods to convert YARD types to Sorbet types.
8
+ # Contains methods to convert YARD types to Parlour types.
8
9
  module TypeConverter
9
- # A regular expression which matches Ruby namespaces and identifiers.
10
+ # A regular expression which matches Ruby namespaces and identifiers.
10
11
  # "Foo", "Foo::Bar", and "::Foo::Bar" are all matches, whereas "Foo.Bar"
11
12
  # or "Foo#bar" are not.
12
13
  SIMPLE_TYPE_REGEX =
@@ -19,27 +20,26 @@ module Sord
19
20
  # "Hash{String => Symbol}", etc.
20
21
  GENERIC_TYPE_REGEX =
21
22
  /(#{SIMPLE_TYPE_REGEX})\s*[<{]\s*(.*)\s*[>}]/
22
-
23
+
23
24
  # Match duck types which require the object implement one or more methods,
24
25
  # like '#foo', '#foo & #bar', '#foo&#bar&#baz', and '#foo&#bar&#baz&#foo_bar'.
25
26
  DUCK_TYPE_REGEX =
26
27
  /^\#[a-zA-Z_][\w]*(?:[a-zA-Z_][\w=]*)*(?:( ?\& ?\#)*[a-zA-Z_][\w=]*)*$/
27
-
28
+
28
29
  # A regular expression which matches ordered lists in the format of
29
30
  # either "Array(String, Symbol)" or "(String, Symbol)".
30
31
  ORDERED_LIST_REGEX = /^(?:Array|)\((.*)\s*\)$/
31
32
 
32
- # A regular expression which matches the shorthand Hash syntax,
33
+ # A regular expression which matches the shorthand Hash syntax,
33
34
  # "{String => Symbol}".
34
35
  SHORTHAND_HASH_SYNTAX = /^{\s*(.*)\s*}$/
35
36
 
36
- # A regular expression which matches the shorthand Array syntax,
37
+ # A regular expression which matches the shorthand Array syntax,
37
38
  # "<String>".
38
39
  SHORTHAND_ARRAY_SYNTAX = /^<\s*(.*)\s*>$/
39
40
 
40
- # An array of built-in generic types supported by Sorbet.
41
- SORBET_SUPPORTED_GENERIC_TYPES = %w{Array Set Enumerable Enumerator Range Hash Class}
42
- SORBET_SINGLE_ARG_GENERIC_TYPES = %w{Array Set Enumerable Enumerator Range}
41
+ # Built in parlour single arg generics
42
+ SINGLE_ARG_GENERIC_TYPES = %w{Array Set Enumerable Enumerator Range}
43
43
 
44
44
  # Given a string of YARD type parameters (without angle brackets), splits
45
45
  # the string into an array of each type parameter.
@@ -50,7 +50,7 @@ module Sord
50
50
  buffer = ""
51
51
  current_bracketing_level = 0
52
52
  character_pointer = 0
53
-
53
+
54
54
  while character_pointer < params.length
55
55
  should_buffer = true
56
56
 
@@ -90,7 +90,7 @@ module Sord
90
90
  result
91
91
  end
92
92
 
93
- # Converts a YARD type into a Sorbet type.
93
+ # Converts a YARD type into a Parlour type.
94
94
  # @param [Boolean, Array, String] yard The YARD type.
95
95
  # @param [YARD::CodeObjects::Base] item The CodeObject which the YARD type
96
96
  # is associated with. This is used for logging and can be nil, but this
@@ -99,30 +99,34 @@ module Sord
99
99
  # instead of SORD_ERROR_ constants for unknown types.
100
100
  # @param [Boolean] replace_unresolved_with_untyped If true, T.untyped is used
101
101
  # when Sord is unable to resolve a constant.
102
- # @return [String]
103
- def self.yard_to_sorbet(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false)
102
+ # @return [Parlour::Types::Type]
103
+ def self.yard_to_parlour(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false)
104
104
  case yard
105
105
  when nil # Type not specified
106
- "T.untyped"
106
+ Parlour::Types::Untyped.new
107
107
  when "bool", "Bool", "boolean", "Boolean", "true", "false"
108
- "T::Boolean"
108
+ Parlour::Types::Boolean.new
109
109
  when 'self'
110
- item.parent.path
110
+ Parlour::Types::Self.new
111
111
  when Array
112
112
  # If there's only one element, unwrap it, otherwise allow for a
113
113
  # selection of any of the types
114
114
  types = yard
115
115
  .reject { |x| x == 'nil' }
116
- .map { |x| yard_to_sorbet(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
117
- .uniq
118
- result = types.length == 1 ? types.first : "T.any(#{types.join(', ')})"
119
- result = "T.nilable(#{result})" if yard.include?('nil')
116
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
117
+ .uniq(&:hash)
118
+ result = types.length == 1 \
119
+ ? types.first
120
+ : Parlour::Types::Union.new(types)
121
+ result = Parlour::Types::Nilable.new(result) if yard.include?('nil')
120
122
  result
121
123
  when /^#{SIMPLE_TYPE_REGEX}$/
122
- if SORBET_SINGLE_ARG_GENERIC_TYPES.include?(yard)
123
- return "T::#{yard}[T.untyped]"
124
+ if SINGLE_ARG_GENERIC_TYPES.include?(yard)
125
+ return Parlour::Types.const_get(yard).new(Parlour::Types::Untyped.new)
124
126
  elsif yard == "Hash"
125
- return "T::Hash[T.untyped, T.untyped]"
127
+ return Parlour::Types::Hash.new(
128
+ Parlour::Types::Untyped.new, Parlour::Types::Untyped.new
129
+ )
126
130
  end
127
131
  # If this doesn't begin with an uppercase letter, warn
128
132
  if /^[_a-z]/ === yard
@@ -136,78 +140,79 @@ module Sord
136
140
  new_path = Resolver.path_for(yard)
137
141
  Logging.infer("#{yard} was resolved to #{new_path}", item) \
138
142
  unless yard == new_path
139
- new_path
143
+ Parlour::Types::Raw.new(new_path)
140
144
  else
141
145
  if replace_unresolved_with_untyped
142
- Logging.warn("#{yard} wasn't able to be resolved to a constant in this project, replaced with T.untyped", item)
143
- 'T.untyped'
146
+ Logging.warn("#{yard} wasn't able to be resolved to a constant in this project, replaced with untyped", item)
147
+ Parlour::Types::Untyped.new
144
148
  else
145
149
  Logging.warn("#{yard} wasn't able to be resolved to a constant in this project", item)
146
- yard
150
+ Parlour::Types::Raw.new(yard)
147
151
  end
148
152
  end
149
153
  else
150
- yard
154
+ Parlour::Types::Raw.new(yard)
151
155
  end
152
156
  when DUCK_TYPE_REGEX
153
- Logging.duck("#{yard} looks like a duck type, replacing with T.untyped", item)
154
- 'T.untyped'
157
+ Logging.duck("#{yard} looks like a duck type, replacing with untyped", item)
158
+ Parlour::Types::Untyped.new
155
159
  when /^#{GENERIC_TYPE_REGEX}$/
156
160
  generic_type = $1
157
161
  type_parameters = $2
158
162
 
159
- if SORBET_SUPPORTED_GENERIC_TYPES.include?(generic_type)
160
- parameters = split_type_parameters(type_parameters)
161
- .map { |x| yard_to_sorbet(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
162
- if SORBET_SINGLE_ARG_GENERIC_TYPES.include?(generic_type) && parameters.length > 1
163
- "T::#{generic_type}[T.any(#{parameters.join(', ')})]"
164
- elsif generic_type == 'Class' && parameters.length == 1
165
- "T.class_of(#{parameters.first})"
166
- elsif generic_type == 'Hash'
167
- if parameters.length == 2
168
- "T::Hash[#{parameters.join(', ')}]"
169
- else
170
- handle_sord_error(parameters.join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
171
- end
163
+ parameters = split_type_parameters(type_parameters)
164
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
165
+ if SINGLE_ARG_GENERIC_TYPES.include?(generic_type) && parameters.length > 1
166
+ Parlour::Types.const_get(generic_type).new(Parlour::Types::Union.new(parameters))
167
+ elsif generic_type == 'Class' && parameters.length == 1
168
+ Parlour::Types::Class.new(parameters.first)
169
+ elsif generic_type == 'Hash'
170
+ if parameters.length == 2
171
+ Parlour::Types::Hash.new(*parameters)
172
172
  else
173
- "T::#{generic_type}[#{parameters.join(', ')}]"
173
+ handle_sord_error(parameters.map(&:describe).join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
174
174
  end
175
175
  else
176
- return handle_sord_error(
177
- generic_type,
178
- "unsupported generic type #{generic_type.inspect} in #{yard.inspect}",
179
- item,
180
- replace_errors_with_untyped
181
- )
176
+ if Parlour::Types.const_defined?(generic_type)
177
+ # This generic is built in to parlour, but sord doesn't
178
+ # explicitly know about it.
179
+ Parlour::Types.const_get(generic_type).new(*parameters)
180
+ else
181
+ # This is a user defined generic
182
+ Parlour::Types::Generic.new(
183
+ yard_to_parlour(generic_type),
184
+ parameters
185
+ )
186
+ end
182
187
  end
183
188
  # Converts ordered lists like Array(Symbol, String) or (Symbol, String)
184
- # into Sorbet Tuples like [Symbol, String].
189
+ # into tuples.
185
190
  when ORDERED_LIST_REGEX
186
191
  type_parameters = $1
187
192
  parameters = split_type_parameters(type_parameters)
188
- .map { |x| yard_to_sorbet(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
189
- "[#{parameters.join(', ')}]"
193
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
194
+ Parlour::Types::Tuple.new(parameters)
190
195
  when SHORTHAND_HASH_SYNTAX
191
196
  type_parameters = $1
192
197
  parameters = split_type_parameters(type_parameters)
193
- .map { |x| yard_to_sorbet(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
198
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
194
199
  # Return a warning about an invalid hash when it has more or less than two elements.
195
200
  if parameters.length == 2
196
- "T::Hash[#{parameters.join(', ')}]"
201
+ Parlour::Types::Hash.new(*parameters)
197
202
  else
198
- handle_sord_error(parameters.join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
203
+ handle_sord_error(parameters.map(&:describe).join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
199
204
  end
200
205
  when SHORTHAND_ARRAY_SYNTAX
201
206
  type_parameters = $1
202
207
  parameters = split_type_parameters(type_parameters)
203
- .map { |x| yard_to_sorbet(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
208
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
204
209
  parameters.one? \
205
- ? "T::Array[#{parameters.first}]"
206
- : "T::Array[T.any(#{parameters.join(', ')})]"
210
+ ? Parlour::Types::Array.new(parameters.first)
211
+ : Parlour::Types::Array.new(Parlour::Types::Union.new(parameters))
207
212
  else
208
213
  # Check for literals
209
214
  from_yaml = YAML.load(yard) rescue nil
210
- return from_yaml.class.to_s \
215
+ return Parlour::Types::Raw.new(from_yaml.class.to_s) \
211
216
  if [Symbol, Float, Integer].include?(from_yaml.class)
212
217
 
213
218
  return handle_sord_error(yard.to_s, "#{yard.inspect} does not appear to be a type", item, replace_errors_with_untyped)
@@ -216,14 +221,17 @@ module Sord
216
221
 
217
222
  # Handles SORD_ERRORs.
218
223
  #
219
- # @param [String] name
224
+ # @param [String, Parlour::Types::Type] name
220
225
  # @param [String] log_warning
221
226
  # @param [YARD::CodeObjects::Base] item
222
227
  # @param [Boolean] replace_errors_with_untyped
223
- # @return [String]
228
+ # @return [Parlour::Types::Type]
224
229
  def self.handle_sord_error(name, log_warning, item, replace_errors_with_untyped)
225
230
  Logging.warn(log_warning, item)
226
- return replace_errors_with_untyped ? "T.untyped" : "SORD_ERROR_#{name.gsub(/[^0-9A-Za-z_]/i, '')}"
231
+ str = name.is_a?(Parlour::Types::Type) ? name.describe : name
232
+ return replace_errors_with_untyped \
233
+ ? Parlour::Types::Untyped.new
234
+ : Parlour::Types::Raw.new("SORD_ERROR_#{name.gsub(/[^0-9A-Za-z_]/i, '')}")
227
235
  end
228
236
  end
229
237
  end
@@ -1,4 +1,4 @@
1
1
  # typed: strong
2
2
  module Sord
3
- VERSION = '0.9.0'
3
+ VERSION = '3.0.0.beta.2'
4
4
  end
@@ -1,29 +1,56 @@
1
1
  # typed: strong
2
2
  module Sord
3
- VERSION = T.let('0.8.0', T.untyped)
3
+ VERSION = T.let('3.0.0.beta.2', T.untyped)
4
4
 
5
+ # Handles writing logs to stdout and any other classes which request them.
5
6
  module Logging
6
7
  AVAILABLE_TYPES = T.let([:warn, :info, :duck, :error, :infer, :omit, :done].freeze, T.untyped)
7
8
 
9
+ # _@return_ — The hooks registered on the logger.
8
10
  sig { returns(T::Array[Proc]) }
9
11
  def self.hooks; end
10
12
 
13
+ # _@return_ — Whether log messages should be printed or not. This is
14
+ # used for testing.
11
15
  sig { returns(T::Boolean) }
12
16
  def self.silent?; end
13
17
 
18
+ # Sets whether log messages should be printed or not.
19
+ #
20
+ # _@param_ `value`
14
21
  sig { params(value: T::Boolean).void }
15
22
  def self.silent=(value); end
16
23
 
24
+ # Sets the array of log messages types which should be processed. Any not on
25
+ # this list will be discarded. This should be a subset of AVAILABLE_TYPES.
26
+ #
27
+ # _@param_ `value`
17
28
  sig { params(value: T::Array[Symbol]).void }
18
29
  def self.enabled_types=(value); end
19
30
 
31
+ # Gets the array of log messages types which should be processed. Any not on
32
+ # this list will be discarded.
20
33
  sig { returns(T::Array[Symbol]) }
21
34
  def self.enabled_types; end
22
35
 
36
+ # Returns a boolean indicating whether a given array is a valid value for
37
+ # #enabled_types.
38
+ #
39
+ # _@param_ `value`
23
40
  sig { params(value: T::Array[Symbol]).void }
24
41
  def self.valid_types?(value); end
25
42
 
26
43
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
44
+ # A generic log message writer which is called by all other specific logging
45
+ # methods. This shouldn't be called outside of the Logging class itself.
46
+ #
47
+ # _@param_ `kind` — The kind of log message this is.
48
+ #
49
+ # _@param_ `header` — The prefix for this log message. For consistency, it should be up to five uppercase characters wrapped in square brackets, with some unique colour applied.
50
+ #
51
+ # _@param_ `msg` — The log message to write.
52
+ #
53
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
27
54
  sig do
28
55
  params(
29
56
  kind: Symbol,
@@ -35,38 +62,91 @@ module Sord
35
62
  def self.generic(kind, header, msg, item); end
36
63
 
37
64
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
65
+ # Print a warning message. This should be used for things which require the
66
+ # user's attention but do not prevent the process from stopping.
67
+ #
68
+ # _@param_ `msg` — The log message to write.
69
+ #
70
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
38
71
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
39
72
  def self.warn(msg, item = nil); end
40
73
 
41
74
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
75
+ # Print an info message. This should be used for generic informational
76
+ # messages which the user doesn't need to act on.
77
+ #
78
+ # _@param_ `msg` — The log message to write.
79
+ #
80
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
42
81
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
43
82
  def self.info(msg, item = nil); end
44
83
 
45
84
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
85
+ # Print a duck-typing message. This should be used when the YARD
86
+ # documentation contains duck typing, which isn't supported by Sorbet, so
87
+ # it is substituted for something different.
88
+ #
89
+ # _@param_ `msg` — The log message to write.
90
+ #
91
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
46
92
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
47
93
  def self.duck(msg, item = nil); end
48
94
 
49
95
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
96
+ # Print an error message. This should be used for things which require the
97
+ # current process to stop.
98
+ #
99
+ # _@param_ `msg` — The log message to write.
100
+ #
101
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
50
102
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
51
103
  def self.error(msg, item = nil); end
52
104
 
53
105
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
106
+ # Print an infer message. This should be used when the user should be told
107
+ # that some information has been filled in or guessed for them, and that
108
+ # information is likely correct.
109
+ #
110
+ # _@param_ `msg` — The log message to write.
111
+ #
112
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
54
113
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
55
114
  def self.infer(msg, item = nil); end
56
115
 
57
116
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
117
+ # Print an omit message. This should be used as a special type of warning
118
+ # to alert the user that there is some information missing, but this
119
+ # information is not critical to the completion of the process.
120
+ #
121
+ # _@param_ `msg` — The log message to write.
122
+ #
123
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
58
124
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
59
125
  def self.omit(msg, item = nil); end
60
126
 
61
127
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
128
+ # Print a done message. This should be used when a process completes
129
+ # successfully.
130
+ #
131
+ # _@param_ `msg` — The log message to write.
132
+ #
133
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
62
134
  sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
63
135
  def self.done(msg, item = nil); end
64
136
 
65
137
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
138
+ # Invokes all registered hooks on the logger.
139
+ #
140
+ # _@param_ `kind` — The kind of log message this is.
141
+ #
142
+ # _@param_ `msg` — The log message to write.
143
+ #
144
+ # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
66
145
  sig { params(kind: Symbol, msg: String, item: YARD::CodeObjects::Base).void }
67
146
  def self.invoke_hooks(kind, msg, item); end
68
147
 
69
148
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
149
+ # Adds a hook to the logger.
70
150
  sig { params(blk: T.proc.params(kind: Symbol, msg: String, item: YARD::CodeObjects::Base).void).void }
71
151
  def self.add_hook(&blk); end
72
152
  end
@@ -78,85 +158,159 @@ module Sord
78
158
  sig { void }
79
159
  def self.clear; end
80
160
 
161
+ # _@param_ `name`
81
162
  sig { params(name: String).returns(T::Array[String]) }
82
163
  def self.paths_for(name); end
83
164
 
165
+ # _@param_ `name`
84
166
  sig { params(name: String).returns(T.nilable(String)) }
85
167
  def self.path_for(name); end
86
168
 
87
169
  sig { returns(T::Array[String]) }
88
170
  def self.builtin_classes; end
89
171
 
172
+ # _@param_ `name`
173
+ #
174
+ # _@param_ `item`
90
175
  sig { params(name: String, item: Object).returns(T::Boolean) }
91
176
  def self.resolvable?(name, item); end
92
177
  end
93
178
 
94
- class RbiGenerator
179
+ # Converts the current working directory's YARD registry into an type
180
+ # signature file.
181
+ class Generator
182
+ VALID_MODES = T.let([:rbi, :rbs], T.untyped)
183
+
184
+ # _@return_ — The number of objects this generator has processed so
185
+ # far.
95
186
  sig { returns(Integer) }
96
187
  def object_count; end
97
188
 
98
- # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
99
- sig { returns(T::Array[[String, YARD::CodeObjects::Base, Integer]]) }
100
- def warnings; end
101
-
189
+ # Create a new generator.
190
+ #
191
+ # _@param_ `options`
102
192
  sig { params(options: T::Hash[T.untyped, T.untyped]).void }
103
193
  def initialize(options); end
104
194
 
195
+ # Increment the namespace counter.
105
196
  sig { void }
106
197
  def count_namespace; end
107
198
 
199
+ # Increment the method counter.
108
200
  sig { void }
109
201
  def count_method; end
110
202
 
111
203
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
204
+ # Given a YARD CodeObject, add lines defining its mixins (that is, extends
205
+ # and includes) to the current file. Returns the number of mixins.
206
+ #
207
+ # _@param_ `item`
112
208
  sig { params(item: YARD::CodeObjects::Base).returns(Integer) }
113
209
  def add_mixins(item); end
114
210
 
115
211
  # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
212
+ # Given a YARD NamespaceObject, add lines defining constants.
213
+ #
214
+ # _@param_ `item`
116
215
  sig { params(item: YARD::CodeObjects::NamespaceObject).void }
117
216
  def add_constants(item); end
118
217
 
119
218
  # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
219
+ # sord warn - Parlour::TypedObject wasn't able to be resolved to a constant in this project
220
+ # Adds comments to an object based on a docstring.
221
+ #
222
+ # _@param_ `item`
223
+ #
224
+ # _@param_ `typed_object`
225
+ sig { params(item: YARD::CodeObjects::NamespaceObject, typed_object: Parlour::TypedObject).void }
226
+ def add_comments(item, typed_object); end
227
+
228
+ # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
229
+ # Given a YARD NamespaceObject, add lines defining its methods and their
230
+ # signatures to the current file.
231
+ #
232
+ # _@param_ `item`
120
233
  sig { params(item: YARD::CodeObjects::NamespaceObject).void }
121
234
  def add_methods(item); end
122
235
 
123
236
  # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
237
+ # Given a YARD NamespaceObject, add lines defining either its class
238
+ # and instance attributes and their signatures to the current file.
239
+ #
240
+ # _@param_ `item`
241
+ sig { params(item: YARD::CodeObjects::NamespaceObject).void }
242
+ def add_attributes(item); end
243
+
244
+ # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
245
+ # Given a YARD NamespaceObject, add lines defining its mixins, methods
246
+ # and children to the file.
247
+ #
248
+ # _@param_ `item`
124
249
  sig { params(item: YARD::CodeObjects::NamespaceObject).void }
125
250
  def add_namespace(item); end
126
251
 
252
+ # Populates the generator with the contents of the YARD registry. You
253
+ # must load the YARD registry first!
127
254
  sig { void }
128
255
  def populate; end
129
256
 
257
+ # Populates the generator with the contents of the YARD registry, then
258
+ # uses the loaded Parlour::Generator to generate the file. You must
259
+ # load the YARD registry first!
130
260
  sig { void }
131
261
  def generate; end
132
262
 
263
+ # Loads the YARD registry, populates the file, and prints any relevant
264
+ # final logs.
133
265
  sig { void }
134
266
  def run; end
135
- end
136
-
137
- class ParlourPlugin < Parlour::Plugin
138
- # sord omit - no YARD return type given, using T.untyped
139
- sig { returns(T.untyped) }
140
- def options; end
141
267
 
142
- # sord omit - no YARD return type given, using T.untyped
143
- sig { returns(T.untyped) }
144
- def parlour; end
268
+ # Given two pairs of arrays representing method parameters, in the form
269
+ # of ["variable_name", "default_value"], sort the parameters so they're
270
+ # valid for Sorbet. Sorbet requires that, e.g. required kwargs go before
271
+ # optional kwargs.
272
+ #
273
+ # _@param_ `pair1`
274
+ #
275
+ # _@param_ `pair2`
276
+ #
277
+ # _@return_ — Integer
278
+ sig { params(pair1: T::Array[T.untyped], pair2: T::Array[T.untyped]).returns(T.untyped) }
279
+ def sort_params(pair1, pair2); end
145
280
 
146
- # sord omit - no YARD return type given, using T.untyped
147
- sig { params(value: T.untyped).returns(T.untyped) }
148
- def parlour=(value); end
281
+ # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
282
+ # _@return_ The
283
+ # errors encountered by by the generator. Each element is of the form
284
+ # [message, item, line].
285
+ sig { returns(T::Array[[String, YARD::CodeObjects::Base, Integer]]) }
286
+ attr_reader :warnings
287
+ end
149
288
 
150
- # sord omit - no YARD type given for "options", using T.untyped
151
- sig { params(options: T.untyped).returns(ParlourPlugin) }
289
+ class ParlourPlugin < Parlour::Plugin
290
+ # sord omit - no YARD type given for "options", using untyped
291
+ sig { params(options: T.untyped).void }
152
292
  def initialize(options); end
153
293
 
154
- # sord omit - no YARD type given for "root", using T.untyped
155
- # sord omit - no YARD return type given, using T.untyped
294
+ # sord omit - no YARD type given for "root", using untyped
295
+ # sord omit - no YARD return type given, using untyped
156
296
  sig { params(root: T.untyped).returns(T.untyped) }
157
297
  def generate(root); end
298
+
299
+ # sord omit - no YARD return type given, using untyped
300
+ sig { params(block: T.untyped).returns(T.untyped) }
301
+ def self.with_clean_env(&block); end
302
+
303
+ # sord omit - no YARD type given for :options, using untyped
304
+ # Returns the value of attribute options.
305
+ sig { returns(T.untyped) }
306
+ attr_reader :options
307
+
308
+ # Returns the value of attribute parlour.
309
+ sig { returns(T.untyped) }
310
+ attr_accessor :parlour
158
311
  end
159
312
 
313
+ # Contains methods to convert YARD types to Parlour types.
160
314
  module TypeConverter
161
315
  SIMPLE_TYPE_REGEX = T.let(/(?:\:\:)?[a-zA-Z_][\w]*(?:\:\:[a-zA-Z_][\w]*)*/, T.untyped)
162
316
  GENERIC_TYPE_REGEX = T.let(/(#{SIMPLE_TYPE_REGEX})\s*[<{]\s*(.*)\s*[>}]/, T.untyped)
@@ -164,32 +318,58 @@ module Sord
164
318
  ORDERED_LIST_REGEX = T.let(/^(?:Array|)\((.*)\s*\)$/, T.untyped)
165
319
  SHORTHAND_HASH_SYNTAX = T.let(/^{\s*(.*)\s*}$/, T.untyped)
166
320
  SHORTHAND_ARRAY_SYNTAX = T.let(/^<\s*(.*)\s*>$/, T.untyped)
167
- SORBET_SUPPORTED_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range Hash Class}, T.untyped)
168
- SORBET_SINGLE_ARG_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range}, T.untyped)
169
-
321
+ SINGLE_ARG_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range}, T.untyped)
322
+
323
+ # Given a string of YARD type parameters (without angle brackets), splits
324
+ # the string into an array of each type parameter.
325
+ #
326
+ # _@param_ `params` — The type parameters.
327
+ #
328
+ # _@return_ — The split type parameters.
170
329
  sig { params(params: String).returns(T::Array[String]) }
171
330
  def self.split_type_parameters(params); end
172
331
 
173
332
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
333
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
334
+ # Converts a YARD type into a Parlour type.
335
+ #
336
+ # _@param_ `yard` — The YARD type.
337
+ #
338
+ # _@param_ `item` — The CodeObject which the YARD type is associated with. This is used for logging and can be nil, but this will lead to less informative log messages.
339
+ #
340
+ # _@param_ `replace_errors_with_untyped` — If true, T.untyped is used instead of SORD_ERROR_ constants for unknown types.
341
+ #
342
+ # _@param_ `replace_unresolved_with_untyped` — If true, T.untyped is used when Sord is unable to resolve a constant.
174
343
  sig do
175
344
  params(
176
345
  yard: T.any(T::Boolean, T::Array[T.untyped], String),
177
346
  item: T.nilable(YARD::CodeObjects::Base),
178
347
  replace_errors_with_untyped: T::Boolean,
179
348
  replace_unresolved_with_untyped: T::Boolean
180
- ).returns(String)
349
+ ).returns(Parlour::Types::Type)
181
350
  end
182
- def self.yard_to_sorbet(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false); end
351
+ def self.yard_to_parlour(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false); end
183
352
 
353
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
184
354
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
355
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
356
+ # Handles SORD_ERRORs.
357
+ #
358
+ # _@param_ `name`
359
+ #
360
+ # _@param_ `log_warning`
361
+ #
362
+ # _@param_ `item`
363
+ #
364
+ # _@param_ `replace_errors_with_untyped`
185
365
  sig do
186
366
  params(
187
- name: String,
367
+ name: T.any(String, Parlour::Types::Type),
188
368
  log_warning: String,
189
369
  item: YARD::CodeObjects::Base,
190
370
  replace_errors_with_untyped: T::Boolean
191
- ).returns(String)
371
+ ).returns(Parlour::Types::Type)
192
372
  end
193
373
  def self.handle_sord_error(name, log_warning, item, replace_errors_with_untyped); end
194
374
  end
195
- end
375
+ end