sord 3.0.1 → 5.0.0

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.
data/rbi/sord.rbi CHANGED
@@ -1,7 +1,7 @@
1
1
  # typed: strong
2
-
2
+ # typed: strong
3
3
  module Sord
4
- VERSION = T.let('3.0.1', T.untyped)
4
+ VERSION = T.let('5.0.0', T.untyped)
5
5
 
6
6
  # Handles writing logs to stdout and any other classes which request them.
7
7
  module Logging
@@ -42,6 +42,7 @@ module Sord
42
42
  def self.valid_types?(value); end
43
43
 
44
44
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
45
+ # sord omit - no YARD type given for "**opts", using untyped
45
46
  # A generic log message writer which is called by all other specific logging
46
47
  # methods. This shouldn't be called outside of the Logging class itself.
47
48
  #
@@ -57,32 +58,36 @@ module Sord
57
58
  kind: Symbol,
58
59
  header: String,
59
60
  msg: String,
60
- item: YARD::CodeObjects::Base
61
+ item: YARD::CodeObjects::Base,
62
+ opts: T.untyped
61
63
  ).void
62
64
  end
63
- def self.generic(kind, header, msg, item); end
65
+ def self.generic(kind, header, msg, item, **opts); end
64
66
 
65
67
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
68
+ # sord omit - no YARD type given for "**opts", using untyped
66
69
  # Print a warning message. This should be used for things which require the
67
70
  # user's attention but do not prevent the process from stopping.
68
71
  #
69
72
  # _@param_ `msg` — The log message to write.
70
73
  #
71
74
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
72
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
73
- def self.warn(msg, item = nil); end
75
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
76
+ def self.warn(msg, item = nil, **opts); end
74
77
 
75
78
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
79
+ # sord omit - no YARD type given for "**opts", using untyped
76
80
  # Print an info message. This should be used for generic informational
77
81
  # messages which the user doesn't need to act on.
78
82
  #
79
83
  # _@param_ `msg` — The log message to write.
80
84
  #
81
85
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
82
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
83
- def self.info(msg, item = nil); end
86
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
87
+ def self.info(msg, item = nil, **opts); end
84
88
 
85
89
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
90
+ # sord omit - no YARD type given for "**opts", using untyped
86
91
  # Print a duck-typing message. This should be used when the YARD
87
92
  # documentation contains duck typing, which isn't supported by Sorbet, so
88
93
  # it is substituted for something different.
@@ -90,20 +95,22 @@ module Sord
90
95
  # _@param_ `msg` — The log message to write.
91
96
  #
92
97
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
93
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
94
- def self.duck(msg, item = nil); end
98
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
99
+ def self.duck(msg, item = nil, **opts); end
95
100
 
96
101
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
102
+ # sord omit - no YARD type given for "**opts", using untyped
97
103
  # Print an error message. This should be used for things which require the
98
104
  # current process to stop.
99
105
  #
100
106
  # _@param_ `msg` — The log message to write.
101
107
  #
102
108
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
103
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
104
- def self.error(msg, item = nil); end
109
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
110
+ def self.error(msg, item = nil, **opts); end
105
111
 
106
112
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
113
+ # sord omit - no YARD type given for "**opts", using untyped
107
114
  # Print an infer message. This should be used when the user should be told
108
115
  # that some information has been filled in or guessed for them, and that
109
116
  # information is likely correct.
@@ -111,10 +118,11 @@ module Sord
111
118
  # _@param_ `msg` — The log message to write.
112
119
  #
113
120
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
114
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
115
- def self.infer(msg, item = nil); end
121
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
122
+ def self.infer(msg, item = nil, **opts); end
116
123
 
117
124
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
125
+ # sord omit - no YARD type given for "**opts", using untyped
118
126
  # Print an omit message. This should be used as a special type of warning
119
127
  # to alert the user that there is some information missing, but this
120
128
  # information is not critical to the completion of the process.
@@ -122,20 +130,22 @@ module Sord
122
130
  # _@param_ `msg` — The log message to write.
123
131
  #
124
132
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
125
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
126
- def self.omit(msg, item = nil); end
133
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
134
+ def self.omit(msg, item = nil, **opts); end
127
135
 
128
136
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
137
+ # sord omit - no YARD type given for "**opts", using untyped
129
138
  # Print a done message. This should be used when a process completes
130
139
  # successfully.
131
140
  #
132
141
  # _@param_ `msg` — The log message to write.
133
142
  #
134
143
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
135
- sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base)).void }
136
- def self.done(msg, item = nil); end
144
+ sig { params(msg: String, item: T.nilable(YARD::CodeObjects::Base), opts: T.untyped).void }
145
+ def self.done(msg, item = nil, **opts); end
137
146
 
138
147
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
148
+ # sord omit - no YARD type given for "**opts", using untyped
139
149
  # Invokes all registered hooks on the logger.
140
150
  #
141
151
  # _@param_ `kind` — The kind of log message this is.
@@ -143,8 +153,15 @@ module Sord
143
153
  # _@param_ `msg` — The log message to write.
144
154
  #
145
155
  # _@param_ `item` — The CodeObject which this log is associated with, if any. This is shown before the log message if it is specified.
146
- sig { params(kind: Symbol, msg: String, item: YARD::CodeObjects::Base).void }
147
- def self.invoke_hooks(kind, msg, item); end
156
+ sig do
157
+ params(
158
+ kind: Symbol,
159
+ msg: String,
160
+ item: YARD::CodeObjects::Base,
161
+ opts: T.untyped
162
+ ).void
163
+ end
164
+ def self.invoke_hooks(kind, msg, item, **opts); end
148
165
 
149
166
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
150
167
  # Adds a hook to the logger.
@@ -156,6 +173,25 @@ module Sord
156
173
  sig { void }
157
174
  def self.prepare; end
158
175
 
176
+ # sord omit - no YARD type given for "hash", using untyped
177
+ # sord omit - no YARD return type given, using untyped
178
+ sig { params(hash: T.untyped).returns(T.untyped) }
179
+ def self.load_gem_objects(hash); end
180
+
181
+ # sord omit - no YARD type given for "all_decls", using untyped
182
+ # sord omit - no YARD type given for "names_to_paths", using untyped
183
+ # sord omit - no YARD type given for "path", using untyped
184
+ # sord omit - no YARD return type given, using untyped
185
+ sig { params(all_decls: T.untyped, names_to_paths: T.untyped, path: T.untyped).returns(T.untyped) }
186
+ def self.add_rbs_objects_to_paths(all_decls, names_to_paths, path = []); end
187
+
188
+ # sord omit - no YARD type given for "nodes", using untyped
189
+ # sord omit - no YARD type given for "names_to_paths", using untyped
190
+ # sord omit - no YARD type given for "path", using untyped
191
+ # sord omit - no YARD return type given, using untyped
192
+ sig { params(nodes: T.untyped, names_to_paths: T.untyped, path: T.untyped).returns(T.untyped) }
193
+ def self.add_rbi_objects_to_paths(nodes, names_to_paths, path = []); end
194
+
159
195
  sig { void }
160
196
  def self.clear; end
161
197
 
@@ -182,7 +218,7 @@ module Sord
182
218
  class Generator
183
219
  VALID_MODES = T.let([:rbi, :rbs], T.untyped)
184
220
 
185
- # _@return_ — The number of objects this generator has processed so
221
+ # _@return_ — The number of objects this generator has processed so
186
222
  # far.
187
223
  sig { returns(Integer) }
188
224
  def object_count; end
@@ -217,7 +253,6 @@ module Sord
217
253
  def add_constants(item); end
218
254
 
219
255
  # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
220
- # sord warn - Parlour::TypedObject wasn't able to be resolved to a constant in this project
221
256
  # Adds comments to an object based on a docstring.
222
257
  #
223
258
  # _@param_ `item`
@@ -226,6 +261,22 @@ module Sord
226
261
  sig { params(item: YARD::CodeObjects::NamespaceObject, typed_object: Parlour::TypedObject).void }
227
262
  def add_comments(item, typed_object); end
228
263
 
264
+ # sord warn - YARD::CodeObjects::MethodObject wasn't able to be resolved to a constant in this project
265
+ # sord warn - YARD::Tags::Tag wasn't able to be resolved to a constant in this project
266
+ # _@param_ `method`
267
+ #
268
+ # _@param_ `tag_name`
269
+ sig { params(method: YARD::CodeObjects::MethodObject, tag_name: String).returns(T::Array[YARD::Tags::Tag]) }
270
+ def method_tags(method, tag_name); end
271
+
272
+ # sord warn - YARD::CodeObjects::MethodObject wasn't able to be resolved to a constant in this project
273
+ # sord warn - YARD::Tags::Tag wasn't able to be resolved to a constant in this project
274
+ # _@param_ `method`
275
+ #
276
+ # _@param_ `tag_name`
277
+ sig { params(method: YARD::CodeObjects::MethodObject, tag_name: String).returns(T.nilable(YARD::Tags::Tag)) }
278
+ def method_tag(method, tag_name); end
279
+
229
280
  # sord warn - YARD::CodeObjects::NamespaceObject wasn't able to be resolved to a constant in this project
230
281
  # Given a YARD NamespaceObject, add lines defining its methods and their
231
282
  # signatures to the current file.
@@ -250,7 +301,7 @@ module Sord
250
301
  sig { params(item: YARD::CodeObjects::NamespaceObject).void }
251
302
  def add_namespace(item); end
252
303
 
253
- # Populates the generator with the contents of the YARD registry. You
304
+ # Populates the generator with the contents of the YARD registry. You
254
305
  # must load the YARD registry first!
255
306
  sig { void }
256
307
  def populate; end
@@ -279,8 +330,15 @@ module Sord
279
330
  sig { params(pair1: T::Array[T.untyped], pair2: T::Array[T.untyped]).returns(T.untyped) }
280
331
  def sort_params(pair1, pair2); end
281
332
 
333
+ # Removes the last character of a default parameter value if it begins with
334
+ # '-', working around a bug in YARD. (See lsegal/yard #894)
335
+ #
336
+ # _@param_ `default`
337
+ sig { params(default: String).returns(T.nilable(String)) }
338
+ def fix_default_if_unary_minus(default); end
339
+
282
340
  # sord warn - YARD::CodeObjects::Base wasn't able to be resolved to a constant in this project
283
- # _@return_ — The
341
+ # _@return_ — The
284
342
  # errors encountered by by the generator. Each element is of the form
285
343
  # [message, item, line].
286
344
  sig { returns(T::Array[[String, YARD::CodeObjects::Base, Integer]]) }
@@ -297,6 +355,10 @@ module Sord
297
355
  sig { params(root: T.untyped).returns(T.untyped) }
298
356
  def generate(root); end
299
357
 
358
+ # sord omit - no YARD return type given, using untyped
359
+ sig { returns(T.untyped) }
360
+ def add_custom_tags; end
361
+
300
362
  # sord omit - no YARD return type given, using untyped
301
363
  sig { params(block: T.untyped).returns(T.untyped) }
302
364
  def self.with_clean_env(&block); end
@@ -315,11 +377,33 @@ module Sord
315
377
  module TypeConverter
316
378
  SIMPLE_TYPE_REGEX = T.let(/(?:\:\:)?[a-zA-Z_][\w]*(?:\:\:[a-zA-Z_][\w]*)*/, T.untyped)
317
379
  GENERIC_TYPE_REGEX = T.let(/(#{SIMPLE_TYPE_REGEX})\s*[<{]\s*(.*)\s*[>}]/, T.untyped)
318
- DUCK_TYPE_REGEX = T.let(/^\#[a-zA-Z_][\w]*(?:[a-zA-Z_][\w=]*)*(?:( ?\& ?\#)*[a-zA-Z_][\w=]*)*$/, T.untyped)
380
+ METHOD_NAME_REGEX = T.let(/(?:[a-z_]\w*[?!=]?|\[\]=?|<<|>>|\*\*|[!~+\*\/%&^|-]|[<>]=?|<=>|={2,3}|![=~]|=~)/i, T.untyped)
381
+ DUCK_TYPE_REGEX = T.let(/^\##{METHOD_NAME_REGEX}(?:\s*\&\s*\##{METHOD_NAME_REGEX})*$/, T.untyped)
319
382
  ORDERED_LIST_REGEX = T.let(/^(?:Array|)\((.*)\s*\)$/, T.untyped)
320
383
  SHORTHAND_HASH_SYNTAX = T.let(/^{\s*(.*)\s*}$/, T.untyped)
321
384
  SHORTHAND_ARRAY_SYNTAX = T.let(/^<\s*(.*)\s*>$/, T.untyped)
322
385
  SINGLE_ARG_GENERIC_TYPES = T.let(%w{Array Set Enumerable Enumerator Range}, T.untyped)
386
+ DUCK_TYPES_TO_RBS_TYPE_NAMES = T.let({
387
+ # Concrete
388
+ "#to_i" => "_ToI",
389
+ "#to_int" => "_ToInt",
390
+ "#to_r" => "_ToR",
391
+ "#to_s" => "_ToS",
392
+ "#to_str" => "_ToStr",
393
+ "#to_proc" => "_ToProc",
394
+ "#to_path" => "_ToPath",
395
+ "#read" => "_Reader",
396
+ "#readpartial" => "_ReaderPartial",
397
+ "#write" => "_Writer",
398
+ "#rewind" => "_Rewindable",
399
+ "#to_io" => "_ToIO",
400
+ "#exception" => "_Exception",
401
+
402
+ # Generic - these will be put in a `Types::Raw`, so writing RBS syntax is a little devious,
403
+ # but by their nature we know they'll only be used in an RBS file, so it's probably fine
404
+ "#to_hash" => "_ToHash[untyped, untyped]",
405
+ "#each" => "_Each[untyped]",
406
+ }, T.untyped)
323
407
 
324
408
  # Given a string of YARD type parameters (without angle brackets), splits
325
409
  # the string into an array of each type parameter.
@@ -331,29 +415,17 @@ module Sord
331
415
  def self.split_type_parameters(params); end
332
416
 
333
417
  # 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
418
  # Converts a YARD type into a Parlour type.
336
419
  #
337
420
  # _@param_ `yard` — The YARD type.
338
421
  #
339
422
  # _@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
423
  #
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.
344
- sig do
345
- params(
346
- yard: T.any(T::Boolean, T::Array[T.untyped], String),
347
- item: T.nilable(YARD::CodeObjects::Base),
348
- replace_errors_with_untyped: T::Boolean,
349
- replace_unresolved_with_untyped: T::Boolean
350
- ).returns(Parlour::Types::Type)
351
- end
352
- def self.yard_to_parlour(yard, item = nil, replace_errors_with_untyped = false, replace_unresolved_with_untyped = false); end
424
+ # _@param_ `config` — The generation configuration.
425
+ sig { params(yard: T.any(T::Boolean, T::Array[T.untyped], String), item: YARD::CodeObjects::Base, config: Configuration).returns(Parlour::Types::Type) }
426
+ def self.yard_to_parlour(yard, item, config); end
353
427
 
354
- # sord warn - Parlour::Types::Type wasn't able to be resolved to a constant in this project
355
428
  # 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
429
  # Handles SORD_ERRORs.
358
430
  #
359
431
  # _@param_ `name`
@@ -372,5 +444,40 @@ module Sord
372
444
  ).returns(Parlour::Types::Type)
373
445
  end
374
446
  def self.handle_sord_error(name, log_warning, item, replace_errors_with_untyped); end
447
+
448
+ # Given a YARD duck type string, attempts to convert it to one of a list of pre-defined RBS
449
+ # built-in interfaces.
450
+ #
451
+ # For example, the common duck type `#to_s` has a built-in RBS equivalent `_ToS`.
452
+ #
453
+ # If no such interface exists, returns `nil`.
454
+ #
455
+ # _@param_ `type`
456
+ sig { params(type: String).returns(T.nilable(Parlour::Types::Type)) }
457
+ def self.duck_type_to_rbs_type(type); end
458
+
459
+ # Configuration for how the type converter should work in particular cases.
460
+ class Configuration
461
+ # sord omit - no YARD type given for "replace_errors_with_untyped:", using untyped
462
+ # sord omit - no YARD type given for "replace_unresolved_with_untyped:", using untyped
463
+ # sord omit - no YARD type given for "output_language:", using untyped
464
+ sig { params(replace_errors_with_untyped: T.untyped, replace_unresolved_with_untyped: T.untyped, output_language: T.untyped).void }
465
+ def initialize(replace_errors_with_untyped:, replace_unresolved_with_untyped:, output_language:); end
466
+
467
+ # sord omit - no YARD type given for :output_language, using untyped
468
+ # The language which the generated types will be converted to - one of
469
+ # `:rbi` or `:rbs`.
470
+ sig { returns(T.untyped) }
471
+ attr_accessor :output_language
472
+
473
+ # _@return_ — If true, T.untyped is used instead of SORD_ERROR_
474
+ # constants for unknown types.
475
+ sig { returns(T::Boolean) }
476
+ attr_accessor :replace_errors_with_untyped
477
+
478
+ # _@param_ `replace_unresolved_with_untyped` — If true, T.untyped is used when Sord is unable to resolve a constant.
479
+ sig { returns(T::Boolean) }
480
+ attr_accessor :replace_unresolved_with_untyped
481
+ end
375
482
  end
376
483
  end
data/sord.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'sorbet-runtime'
27
27
  spec.add_dependency 'commander', '~> 4.5'
28
28
  spec.add_dependency 'parlour', '~> 5.0'
29
+ spec.add_dependency 'rbs', '~> 2.0'
29
30
 
30
31
  spec.add_development_dependency "bundler", "~> 2.0"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Christiansen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rbs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +160,7 @@ extra_rdoc_files: []
146
160
  files:
147
161
  - ".github/ISSUE_TEMPLATE/bug_report.md"
148
162
  - ".github/ISSUE_TEMPLATE/feature-request.md"
163
+ - ".github/workflows/ruby.yml"
149
164
  - ".gitignore"
150
165
  - ".parlour"
151
166
  - ".rspec"
@@ -185,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
200
  - !ruby/object:Gem::Version
186
201
  version: '0'
187
202
  requirements: []
188
- rubygems_version: 3.0.3
203
+ rubygems_version: 3.2.22
189
204
  signing_key:
190
205
  specification_version: 4
191
206
  summary: Generate Sorbet RBI files from YARD documentation