sord 2.0.0 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -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,9 +2,10 @@
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
10
  # A regular expression which matches Ruby namespaces and identifiers.
10
11
  # "Foo", "Foo::Bar", and "::Foo::Bar" are all matches, whereas "Foo.Bar"
@@ -37,9 +38,9 @@ module Sord
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
+ # An array of built-in types supported by Parlour.
42
+ SUPPORTED_GENERIC_TYPES = %w{Array Set Enumerable Enumerator Range Hash Class}
43
+ SINGLE_ARG_GENERIC_TYPES = %w{Array Set Enumerable Enumerator Range}
43
44
 
44
45
  # Given a string of YARD type parameters (without angle brackets), splits
45
46
  # the string into an array of each type parameter.
@@ -90,7 +91,7 @@ module Sord
90
91
  result
91
92
  end
92
93
 
93
- # Converts a YARD type into a Sorbet type.
94
+ # Converts a YARD type into a Parlour type.
94
95
  # @param [Boolean, Array, String] yard The YARD type.
95
96
  # @param [YARD::CodeObjects::Base] item The CodeObject which the YARD type
96
97
  # is associated with. This is used for logging and can be nil, but this
@@ -99,30 +100,34 @@ module Sord
99
100
  # instead of SORD_ERROR_ constants for unknown types.
100
101
  # @param [Boolean] replace_unresolved_with_untyped If true, T.untyped is used
101
102
  # 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)
103
+ # @return [Parlour::Types::Type]
104
+ def self.yard_to_parlour(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false)
104
105
  case yard
105
106
  when nil # Type not specified
106
- "T.untyped"
107
+ Parlour::Types::Untyped.new
107
108
  when "bool", "Bool", "boolean", "Boolean", "true", "false"
108
- "T::Boolean"
109
+ Parlour::Types::Boolean.new
109
110
  when 'self'
110
- 'T.self_type'
111
+ Parlour::Types::Self.new
111
112
  when Array
112
113
  # If there's only one element, unwrap it, otherwise allow for a
113
114
  # selection of any of the types
114
115
  types = yard
115
116
  .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')
117
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
118
+ .uniq(&:hash)
119
+ result = types.length == 1 \
120
+ ? types.first
121
+ : Parlour::Types::Union.new(types)
122
+ result = Parlour::Types::Nilable.new(result) if yard.include?('nil')
120
123
  result
121
124
  when /^#{SIMPLE_TYPE_REGEX}$/
122
- if SORBET_SINGLE_ARG_GENERIC_TYPES.include?(yard)
123
- return "T::#{yard}[T.untyped]"
125
+ if SINGLE_ARG_GENERIC_TYPES.include?(yard)
126
+ return Parlour::Types.const_get(yard).new(Parlour::Types::Untyped.new)
124
127
  elsif yard == "Hash"
125
- return "T::Hash[T.untyped, T.untyped]"
128
+ return Parlour::Types::Hash.new(
129
+ Parlour::Types::Untyped.new, Parlour::Types::Untyped.new
130
+ )
126
131
  end
127
132
  # If this doesn't begin with an uppercase letter, warn
128
133
  if /^[_a-z]/ === yard
@@ -136,41 +141,41 @@ module Sord
136
141
  new_path = Resolver.path_for(yard)
137
142
  Logging.infer("#{yard} was resolved to #{new_path}", item) \
138
143
  unless yard == new_path
139
- new_path
144
+ Parlour::Types::Raw.new(new_path)
140
145
  else
141
146
  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'
147
+ Logging.warn("#{yard} wasn't able to be resolved to a constant in this project, replaced with untyped", item)
148
+ Parlour::Types::Untyped.new
144
149
  else
145
150
  Logging.warn("#{yard} wasn't able to be resolved to a constant in this project", item)
146
- yard
151
+ Parlour::Types::Raw.new(yard)
147
152
  end
148
153
  end
149
154
  else
150
- yard
155
+ Parlour::Types::Raw.new(yard)
151
156
  end
152
157
  when DUCK_TYPE_REGEX
153
- Logging.duck("#{yard} looks like a duck type, replacing with T.untyped", item)
154
- 'T.untyped'
158
+ Logging.duck("#{yard} looks like a duck type, replacing with untyped", item)
159
+ Parlour::Types::Untyped.new
155
160
  when /^#{GENERIC_TYPE_REGEX}$/
156
161
  generic_type = $1
157
162
  type_parameters = $2
158
163
 
159
- if SORBET_SUPPORTED_GENERIC_TYPES.include?(generic_type)
164
+ if SUPPORTED_GENERIC_TYPES.include?(generic_type)
160
165
  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(', ')})]"
166
+ .map { |x| yard_to_parlour(x, item, replace_errors_with_untyped, replace_unresolved_with_untyped) }
167
+ if SINGLE_ARG_GENERIC_TYPES.include?(generic_type) && parameters.length > 1
168
+ Parlour::Types.const_get(generic_type).new(Parlour::Types::Union.new(parameters))
164
169
  elsif generic_type == 'Class' && parameters.length == 1
165
- "T.class_of(#{parameters.first})"
170
+ Parlour::Types::Class.new(parameters.first)
166
171
  elsif generic_type == 'Hash'
167
172
  if parameters.length == 2
168
- "T::Hash[#{parameters.join(', ')}]"
173
+ Parlour::Types::Hash.new(*parameters)
169
174
  else
170
- handle_sord_error(parameters.join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
175
+ handle_sord_error(parameters.map(&:describe).join, "Invalid hash, must have exactly two types: #{yard.inspect}.", item, replace_errors_with_untyped)
171
176
  end
172
177
  else
173
- "T::#{generic_type}[#{parameters.join(', ')}]"
178
+ Parlour::Types.const_get(generic_type).new(*parameters)
174
179
  end
175
180
  else
176
181
  return handle_sord_error(
@@ -181,33 +186,33 @@ module Sord
181
186
  )
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 = '2.0.0'
3
+ VERSION = '3.0.0.beta.1'
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.1', 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,59 @@ 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
+ SUPPORTED_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range Hash Class}, T.untyped)
322
+ SINGLE_ARG_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range}, T.untyped)
323
+
324
+ # Given a string of YARD type parameters (without angle brackets), splits
325
+ # the string into an array of each type parameter.
326
+ #
327
+ # _@param_ `params` — The type parameters.
328
+ #
329
+ # _@return_ — The split type parameters.
170
330
  sig { params(params: String).returns(T::Array[String]) }
171
331
  def self.split_type_parameters(params); end
172
332
 
173
333
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
334
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
335
+ # Converts a YARD type into a Parlour type.
336
+ #
337
+ # _@param_ `yard` — The YARD type.
338
+ #
339
+ # _@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.
340
+ #
341
+ # _@param_ `replace_errors_with_untyped` — If true, T.untyped is used instead of SORD_ERROR_ constants for unknown types.
342
+ #
343
+ # _@param_ `replace_unresolved_with_untyped` — If true, T.untyped is used when Sord is unable to resolve a constant.
174
344
  sig do
175
345
  params(
176
346
  yard: T.any(T::Boolean, T::Array[T.untyped], String),
177
347
  item: T.nilable(YARD::CodeObjects::Base),
178
348
  replace_errors_with_untyped: T::Boolean,
179
349
  replace_unresolved_with_untyped: T::Boolean
180
- ).returns(String)
350
+ ).returns(Parlour::Types::Type)
181
351
  end
182
- def self.yard_to_sorbet(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false); end
352
+ def self.yard_to_parlour(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false); end
183
353
 
354
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
184
355
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
356
+ # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
357
+ # Handles SORD_ERRORs.
358
+ #
359
+ # _@param_ `name`
360
+ #
361
+ # _@param_ `log_warning`
362
+ #
363
+ # _@param_ `item`
364
+ #
365
+ # _@param_ `replace_errors_with_untyped`
185
366
  sig do
186
367
  params(
187
- name: String,
368
+ name: T.any(String, Parlour::Types::Type),
188
369
  log_warning: String,
189
370
  item: YARD::CodeObjects::Base,
190
371
  replace_errors_with_untyped: T::Boolean
191
- ).returns(String)
372
+ ).returns(Parlour::Types::Type)
192
373
  end
193
374
  def self.handle_sord_error(name, log_warning, item, replace_errors_with_untyped); end
194
375
  end
195
- end
376
+ end