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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfebf9f7b35b936d5a448430b99c0aaa79cb13af0183cdf438c9d210b79fcbe4
4
- data.tar.gz: fd5d9f369fbc55d34bac6b3338cb481a3a0a3ed748d47130327f841e5ac3d8a7
3
+ metadata.gz: 7a96fafb7c0a8a07c5462a5138b836837e65e2dd14f68d9f51ebd502170c84f9
4
+ data.tar.gz: 8d82f8e1848f0422cdd4729933f867f78daffeeb226a54b826d5fd75660e73ac
5
5
  SHA512:
6
- metadata.gz: 0407ed5b5770dd46c40df84dd40ba598d650a237f5f5a59127c66d30078970b36c803165dccbb9c6057784bee7763031f15d081fb0aabede6d100d5e943acd10
7
- data.tar.gz: '07849f1278d3d40a3230c45293bc23d6c5ab31360f1d43a55ebc04eefc448e80481fc740180a776d6d999193798a30e1aa961a406c77e9f92d998a67ae43c4e2'
6
+ metadata.gz: f885ba62dd5b528f63e644d6cc6d000b33f372ea07ec7f372b1231464f5989e5353db508d553d997cdb772dc5ad075cf8fc3d37ede901f16efaa031438b59474
7
+ data.tar.gz: 859a054fdf1e1609035862c4f95d3b03622dcf7fe97c97afae120e80168102af0806dd8463aa00815f2e294cb0c895f511a9387b4f22e8464dc8aa9dc4f9a333
File without changes
File without changes
data/.gitignore CHANGED
File without changes
data/.parlour CHANGED
@@ -1,7 +1,11 @@
1
- output_file: rbi/sord.rbi
1
+ parser: false
2
+
3
+ output_file:
4
+ rbi: rbi/sord.rbi
2
5
 
3
6
  requires:
4
7
  - sord
5
8
 
6
9
  plugins:
7
- Sord::ParlourPlugin: {}
10
+ Sord::ParlourPlugin:
11
+ rbi: yes
data/.rspec CHANGED
File without changes
File without changes
@@ -3,6 +3,64 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5
5
 
6
+ ## [3.0.0.beta.2] - 2020-10-05
7
+ ### Added
8
+ - Sord is no longer limited to a known set of generics, and will instead
9
+ generate `Parlour::Types::Generic` types for user-defined generics.
10
+
11
+ ## [3.0.0.beta.1] - 2020-09-16
12
+ ### Added
13
+ - Sord now uses the Parlour 5 beta's RBS generation to generate RBS files!
14
+ - Added `--rbi` and `--rbs` to select an output format to use (if neither given,
15
+ tries to infer from file extension).
16
+
17
+ ### Changed
18
+ - `RbiGenerator` has been renamed to `Generator`.
19
+ - `TypeConverter#yard_to_sorbet` is now `TypeConverter#yard_to_parlour`, and
20
+ returns `Parlour::Types::Type` instances rather than strings.
21
+
22
+ ### Fixed
23
+ - `#return [nil]` no longer produces a union of zero types, instead becoming
24
+ `void` for method returns or `untyped` for attributes.
25
+
26
+ ## [2.0.0] - 2020-03-16
27
+ ### Added
28
+ - Sord now supports generating `attr_accessor`, `attr_reader` and `attr_writer`
29
+ and will do so automatically when these are used in your code.
30
+ - Depending on what you're doing with Sord, this is **potentially breaking**,
31
+ as for example attributes which would previously generate two `foo` and `foo=`
32
+ methods in Sord will now just generate an `attr_accessor`.
33
+ - `#initialize` is now always typed as returning `void`, which is
34
+ **potentially breaking** if you directly call `#initialize` in code.
35
+ - The `--use-original-initialize-return` flag restores the old behaviour of
36
+ using whatever return type is provided, like any other method.
37
+
38
+ ## [1.0.0] - 2020-02-16
39
+ ### Added
40
+ - Added the `--skip-constants` flag to avoid generating RBIs for constants.
41
+
42
+ ### Changed
43
+ - Parlour 2.0.0 is now being used.
44
+
45
+ ### Fixed
46
+ - Fixed a bug where blank parameters were sometimes treated like non-blank
47
+ parameters.
48
+ - Fixed parameter order sometimes being incorrect.
49
+ - Fixed multiline parameter lists sometimes generating invalid RBIs.
50
+ - Multiline comments are now generated correctly.
51
+ - Fixed an incorrect README link.
52
+
53
+ ## [0.10.0] - 2019-09-14
54
+ ### Added
55
+ - Comments in RBIs are now converted from YARD into Markdown format, making them
56
+ look much better when viewed in an IDE. (To restore the old behaviour of copying
57
+ the YARD comments verbatim, use the `--keep-original-comments` flag.)
58
+
59
+ ### Changed
60
+ - Parlour 0.8.0 is now being used.
61
+ - References to `self` as a type in YARD docs are now generated as
62
+ `T.self_type`, rather than a fixed self type determined by Sord.
63
+
6
64
  ## [0.9.0] - 2019-08-09
7
65
  ### Added
8
66
  - Add the `--replace-constants-with-untyped` flag, which generates `T.untyped` instead of `SORD_ERROR` constants.
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
@@ -2,25 +2,28 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://sorbet.org)
6
- crossover. It can automatically generate Sorbet type signatures files by
7
- looking at the types specified in YARD documentation comments.
5
+ Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://yardoc.org/)
6
+ crossover. It can **automatically generate RBI and RBS type signature files** by
7
+ looking at the **types specified in YARD documentation** comments.
8
8
 
9
9
  If your project is already YARD documented, then this can generate most of the
10
- Sorbet signatures you need!
10
+ type signatures you need!
11
+
12
+ Sord is the perfect way to jump-start the adoption of types in your project,
13
+ whether you plan to use Sorbet's RBI format or Ruby 3/Steep's RBS format.
11
14
 
12
15
  Sord has the following features:
13
16
  - Automatically generates signatures for modules, classes and methods
14
- - Support for multiple parameter or return types (`T.any`)
15
- - Gracefully handles missing YARD types (`T.untyped`)
17
+ - Support for multiple parameter or return types (`T.any`/`|`)
18
+ - Gracefully handles missing YARD types (`T.untyped`/`untyped`)
16
19
  - Can infer setter parameter type from the corresponding getter's return type
17
20
  - Recognises mixins (`include` and `extend`)
18
21
  - Support for generic types such as `Array<T>` and `Hash<K, V>`
19
22
  - Can infer namespaced classes (`[Bar]` can become `GemName::Foo::Bar`)
20
- - Handles return types which can be `nil` (`T.nilable`)
21
- - Handles duck types (`T.untyped`)
23
+ - Handles return types which can be `nil` (`T.nilable`/`untyped`)
24
+ - Handles duck types (`T.untyped`/`untyped`)
22
25
  - Support for ordered list types (`[Array(Integer, Symbol)]` becomes `[Integer, Symbol]`)
23
- - Support for boolean types (`[true, false]` becomes `T::Boolean`)
26
+ - Support for boolean types (`[true, false]` becomes `T::Boolean`/`bool`)
24
27
  - Support for `&block` parameters documented with `@yieldparam` and `@yieldreturn`
25
28
 
26
29
  ## Usage
@@ -29,7 +32,7 @@ Install Sord with `gem install sord`.
29
32
 
30
33
  Sord is a command line tool. To use it, open a terminal in the root directory
31
34
  of your project and invoke `sord`, passing a path where you'd like to save your
32
- `.rbi` (this file will be overwritten):
35
+ file (this file will be overwritten):
33
36
 
34
37
  ```
35
38
  sord defs.rbi
@@ -37,7 +40,12 @@ sord defs.rbi
37
40
 
38
41
  Sord will generate YARD docs and then print information about what it's inferred
39
42
  as it runs. It is best to fix any issues in the YARD documentation, as any edits
40
- made to the resulting RBI file will be replaced if you re-run Sord.
43
+ made to the resulting file will be replaced if you re-run Sord.
44
+
45
+ The output type is inferred by the file extension you use, but you can also
46
+ specify it explicitly with `--rbi` or `--rbs`.
47
+
48
+ ## Shipping RBI Types
41
49
 
42
50
  RBI files generated by Sord can be used in two main ways:
43
51
 
@@ -50,17 +58,22 @@ where the maintainer is unwilling to ship type signatures with the gem itself.
50
58
 
51
59
  ### Flags
52
60
 
53
- Sord also takes some flags to alter the generated `.rbi` file:
61
+ Sord also takes some flags to alter the generated file:
54
62
 
55
- - `--no-comments`: Generates the `.rbi` file without any comments about
56
- warnings/inferences/errors.
63
+ - `--rbi`/`--rbs`: Override the output format inferred from the file
64
+ extension.
65
+ - `--no-sord-comments`: Generates the file without any Sord comments about
66
+ warnings/inferences/errors. (The original file's comments will still be
67
+ included.)
57
68
  - `--no-regenerate`: By default, Sord will regenerate a repository's YARD
58
69
  docs for you. This option skips regenerating the YARD docs.
59
70
  - `--break-params`: Determines how many parameters are necessary before
60
71
  the signature is changed from a single-line to a multi-line block.
61
72
  (Default: 4)
62
- - `--replace-errors-with-untyped`: Uses `T.untyped` instead of `SORD_ERROR_*` constants.
63
- - `--replace-unresolved-with-untyped`: Uses `T.untyped` when Sord is unable to resolve a constant.
73
+ - `--replace-errors-with-untyped`: Uses `T.untyped` instead of `SORD_ERROR_*`
74
+ constants.
75
+ - `--replace-unresolved-with-untyped`: Uses `T.untyped` when Sord is unable to
76
+ resolve a constant.
64
77
  - `--include-messages` and `--exclude-messages`: Used to filter the logging
65
78
  messages given by Sord. `--include-messages` acts as a whitelist, printing
66
79
  only messages of the specified logging kinds, whereas `--exclude-messages`
@@ -76,22 +89,22 @@ Say we have this file, called `test.rb`:
76
89
  ```ruby
77
90
  module Example
78
91
  class Person
79
- # @param [String] name
80
- # @param [Integer] age
92
+ # @param name [String] The name of the Person to create.
93
+ # @param age [Integer] The age of the Person to create.
81
94
  # @return [Example::Person]
82
95
  def initialize(name, age)
83
96
  @name = name
84
97
  @age = age
85
98
  end
86
99
 
87
- # @return [String] name
100
+ # @return [String]
88
101
  attr_accessor :name
89
102
 
90
- # @return [Integer] age
103
+ # @return [Integer]
91
104
  attr_accessor :age
92
105
 
93
- # @param [Array<String>] possible_names
94
- # @param [Array<Integer>] possible_ages
106
+ # @param possible_names [Array<String>] An array of potential names to choose from.
107
+ # @param possible_ages [Array<Integer>] An array of potential ages to choose from.
95
108
  # @return [Example::Person]
96
109
  def self.construct_randomly(possible_names, possible_ages)
97
110
  Person.new(possible_names.sample, possible_ages.sample)
@@ -105,9 +118,8 @@ First, generate a YARD registry by running `yardoc test.rb`. Then, we can run
105
118
  files! Note the `.rbi` file extension.) In doing this, Sord prints:
106
119
 
107
120
  ```
108
- [INFER] (Example::Person#name=) inferred type of parameter "value" as String using getter's return type
109
- [INFER] (Example::Person#age=) inferred type of parameter "value" as Integer using getter's return type
110
- [DONE ] Processed 8 objects
121
+ [INFER] Assuming from filename you wish to generate in RBI format
122
+ [DONE ] Processed 8 objects (2 namespaces and 6 methods)
111
123
  ```
112
124
 
113
125
  The `test.rbi` file then contains a complete RBI file for `test.rb`:
@@ -116,25 +128,45 @@ The `test.rbi` file then contains a complete RBI file for `test.rb`:
116
128
  # typed: strong
117
129
  module Example
118
130
  class Person
119
- sig { params(name: String, age: Integer).returns(Example::Person) }
131
+ # _@param_ `name` The name of the Person to create.
132
+ #
133
+ # _@param_ `age` — The age of the Person to create.
134
+ sig { params(name: String, age: Integer).void }
120
135
  def initialize(name, age); end
121
136
 
122
- sig { returns(String) }
123
- def name(); end
137
+ # _@param_ `possible_names` — An array of potential names to choose from.
138
+ #
139
+ # _@param_ `possible_ages` — An array of potential ages to choose from.
140
+ sig { params(possible_names: T::Array[String], possible_ages: T::Array[Integer]).returns(Example::Person) }
141
+ def self.construct_randomly(possible_names, possible_ages); end
124
142
 
125
- # sord infer - inferred type of parameter "value" as String using getter's return type
126
- sig { params(value: String).returns(String) }
127
- def name=(value); end
143
+ sig { returns(String) }
144
+ attr_accessor :name
128
145
 
129
146
  sig { returns(Integer) }
130
- def age(); end
147
+ attr_accessor :age
148
+ end
149
+ end
150
+ ```
131
151
 
132
- # sord infer - inferred type of parameter "value" as Integer using getter's return type
133
- sig { params(value: Integer).returns(Integer) }
134
- def age=(value); end
152
+ If we had instead generated `test.rbs`, we would get this file in RBS format:
135
153
 
136
- sig { params(possible_names: T::Array[String], possible_ages: T::Array[Integer]).returns(Example::Person) }
137
- def self.construct_randomly(possible_names, possible_ages); end
154
+ ```ruby
155
+ module Example
156
+ class Person
157
+ # _@param_ `name` — The name of the Person to create.
158
+ #
159
+ # _@param_ `age` — The age of the Person to create.
160
+ def initialize: (String name, Integer age) -> void
161
+
162
+ # _@param_ `possible_names` — An array of potential names to choose from.
163
+ #
164
+ # _@param_ `possible_ages` — An array of potential ages to choose from.
165
+ def self.construct_randomly: (Array[String] possible_names, Array[Integer] possible_ages) -> Example::Person
166
+
167
+ attr_accessor name: String
168
+
169
+ attr_accessor age: Integer
138
170
  end
139
171
  end
140
172
  ```
@@ -143,12 +175,13 @@ end
143
175
 
144
176
  The general rule of thumb for type conversions is:
145
177
 
146
- - If Sord understands the YARD type, then it is converted into the Sorbet type.
178
+ - If Sord understands the YARD type, then it is converted into the RBI or RBS
179
+ type.
147
180
  - If the YARD type is missing, Sord fills in `T.untyped`.
148
181
  - If the YARD type can't be understood, Sord creates an undefined Ruby constant
149
182
  with a similar name to the unknown YARD type. For example, the obviously
150
183
  invalid YARD type `A%B` will become a constant called `SORD_ERROR_AB`.
151
- You should search through your resulting RBI to find and fix and
184
+ You should search through your resulting file to find and fix and
152
185
  `SORD_ERROR`s.
153
186
 
154
187
  ## Contributing
@@ -156,11 +189,11 @@ The general rule of thumb for type conversions is:
156
189
  Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/sord. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
157
190
 
158
191
  While contributing, if you want to see the results of your changes to Sord you
159
- can use the `examples:seed` Rake task. The task uses Sord to generate RBIs for
192
+ can use the `examples:seed` Rake task. The task uses Sord to generate types for
160
193
  a number of open source Ruby gems, including Bundler, Haml, Rouge, and RSpec.
161
- `rake examples:seed` (and `rake examples:reseed` to regenerate the RBI files)
162
- will clone the repositories of these gems into `sord_examples/` and then
163
- generate the RBI files into the same directory.
194
+ `rake examples:seed` (and `rake examples:reseed` to regenerate the files) will
195
+ clone the repositories of these gems into `sord_examples/` and then generate the
196
+ files into the same directory.
164
197
 
165
198
  ## License
166
199
 
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ REPOS = {
10
10
  bundler: 'https://github.com/bundler/bundler',
11
11
  discordrb: 'https://github.com/meew0/discordrb',
12
12
  gitlab: 'https://github.com/NARKOZ/gitlab',
13
+ 'graphql-ruby': 'https://github.com/rmosolgo/graphql-ruby',
13
14
  haml: 'https://github.com/haml/haml',
14
15
  oga: 'https://gitlab.com/yorickpeterse/oga',
15
16
  rouge: 'https://github.com/rouge-ruby/rouge',
@@ -23,12 +24,21 @@ namespace :examples do
23
24
  require 'rainbow'
24
25
 
25
26
  desc "Clone git repositories and run Sord on them as examples"
26
- task :seed, [:clean] do |t, args|
27
+ task :seed, [:mode, :clean] do |t, args|
27
28
  if File.directory?('sord_examples')
28
29
  puts Rainbow('sord_examples directory already exists, please delete the directory or run a reseed!').red
29
30
  exit
30
31
  end
31
32
 
33
+ if args[:mode] == 'rbi'
34
+ mode_arg = '--rbi'
35
+ elsif args[:mode] == 'rbs'
36
+ mode_arg = '--rbs'
37
+ else
38
+ puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
39
+ exit
40
+ end
41
+
32
42
  FileUtils.mkdir 'sord_examples'
33
43
  FileUtils.cd 'sord_examples'
34
44
 
@@ -45,11 +55,11 @@ namespace :examples do
45
55
  # Generate sri
46
56
  puts "Generating rbi for #{name}..."
47
57
  if args[:clean]
48
- system("bundle exec sord ../#{name}.rbi --no-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
58
+ system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
49
59
  else
50
- system("bundle exec sord ../#{name}.rbi")
60
+ system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg}")
51
61
  end
52
- puts "#{name}.rbi generated!"
62
+ puts "#{name}.#{args[:mode]} generated!"
53
63
  FileUtils.cd '..'
54
64
  end
55
65
  end
@@ -58,21 +68,30 @@ namespace :examples do
58
68
  end
59
69
 
60
70
  desc 'Regenerate the rbi files in sord_examples.'
61
- task :reseed, [:clean] do |t, args|
71
+ task :reseed, [:mode, :clean] do |t, args|
62
72
  if Dir.exist?('sord_examples')
63
73
  FileUtils.cd 'sord_examples'
64
74
  else
65
75
  raise Rainbow("The sord_examples directory does not exist. Have you run the seed task?").red.bold
66
76
  end
67
77
 
78
+ if args[:mode] == 'rbi'
79
+ mode_arg = '--rbi'
80
+ elsif args[:mode] == 'rbs'
81
+ mode_arg = '--rbs'
82
+ else
83
+ puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
84
+ exit
85
+ end
86
+
68
87
  REPOS.keys.each do |name|
69
88
  FileUtils.cd name.to_s
70
89
  puts "Regenerating rbi file for #{name}..."
71
90
  Bundler.with_clean_env do
72
91
  if args[:clean]
73
- system("bundle exec sord ../#{name}.rbi --no-regenerate --no-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
92
+ system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
74
93
  else
75
- system("bundle exec sord ../#{name}.rbi --no-regenerate")
94
+ system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate")
76
95
  end
77
96
  end
78
97
  FileUtils.cd '..'
data/exe/sord CHANGED
@@ -10,39 +10,81 @@ program :description, 'Generate Sorbet RBIs from YARD documentation'
10
10
  default_command :gen
11
11
  command :gen do |c|
12
12
  c.syntax = 'sord gen <output-file> [options]'
13
- c.description = 'Generates an RBI file from this directory\'s YARD docs'
14
- c.option '--[no-]comments', 'Controls informational/warning comments in the RBI file'
13
+ c.description = 'Generates a type signature file from this directory\'s YARD docs'
14
+ c.option '--rbi', 'Use Sorbet\'s RBI format'
15
+ c.option '--rbs', 'Use Steep/Ruby 3\'s RBS format'
16
+ c.option '--[no-]sord-comments', 'Controls informational/warning comments in the file'
15
17
  c.option '--[no-]regenerate', 'Controls whether YARD is executed before Sord runs'
16
18
  c.option '--break-params INTEGER', Integer, 'Break params onto their own lines if there are this many'
17
19
  c.option '--replace-errors-with-untyped', 'Uses T.untyped rather than SORD_ERROR_ constants'
18
20
  c.option '--replace-unresolved-with-untyped', 'Uses T.untyped when Sord is unable to resolve a constant'
19
21
  c.option '--exclude-messages STRING', String, 'Blacklists a comma-separated string of log message types'
20
22
  c.option '--include-messages STRING', String, 'Whitelists a comma-separated string of log message types'
23
+ c.option '--keep-original-comments', 'Retains original YARD comments rather than converting them to Markdown'
24
+ c.option '--skip-constants', 'Excludes constants from generated file'
25
+ c.option '--use-original-initialize-return', 'Uses the specified return type for #initialize rather than void'
21
26
 
22
27
  c.action do |args, options|
23
28
  options.default(
24
- comments: true,
29
+ rbi: false,
30
+ rbs: false,
31
+ sord_comments: true,
25
32
  regenerate: true,
26
33
  break_params: 4,
27
34
  replace_errors_with_untyped: false,
28
35
  replace_unresolved_with_untyped: false,
29
36
  exclude_messages: nil,
30
37
  include_messages: nil,
38
+ keep_original_comments: false,
39
+ skip_constants: false,
40
+ use_original_initialize_return: false,
31
41
  )
32
42
 
33
43
  if args.length != 1
34
44
  Sord::Logging.error('Must specify filename')
35
45
  exit 1
36
46
  end
37
-
47
+
38
48
  plugin_options = options.__hash__
39
49
  plugin_options[:exclude_options] = plugin_options[:exclude_options]&.split(',')
40
50
  plugin_options[:include_options] = plugin_options[:include_options]&.split(',')
41
51
 
52
+ if !(plugin_options[:rbi] || plugin_options[:rbs])
53
+ if args.first
54
+ if args.first.end_with?('.rbi')
55
+ Sord::Logging.infer('Assuming from filename you wish to generate in RBI format')
56
+ plugin_options[:rbi] = true
57
+ elsif args.first.end_with?('.rbs')
58
+ Sord::Logging.infer('Assuming from filename you wish to generate in RBS format')
59
+ plugin_options[:rbs] = true
60
+ else
61
+ Sord::Logging.error('An output format could not be inferred from your filename; please specify --rbi or --rbs')
62
+ exit 1
63
+ end
64
+ else
65
+ Sord::Logging.error('No output format given; please specify --rbi or --rbs')
66
+ exit 1
67
+ end
68
+ end
69
+
70
+ if (plugin_options[:rbi] && plugin_options[:rbs])
71
+ Sord::Logging.error('You cannot specify both --rbi and --rbs; please use only one')
72
+ exit 1
73
+ end
74
+
42
75
  plugin = Sord::ParlourPlugin.new(plugin_options)
43
- plugin.parlour = Parlour::RbiGenerator.new(break_params: plugin_options[:break_params])
76
+
77
+ if plugin_options[:rbi]
78
+ klass = Parlour::RbiGenerator
79
+ generator_method = :rbi
80
+ elsif plugin_options[:rbs]
81
+ klass = Parlour::RbsGenerator
82
+ generator_method = :rbs
83
+ end
84
+
85
+ plugin.parlour = klass.new(break_params: plugin_options[:break_params])
44
86
  plugin.generate(plugin.parlour.root)
45
87
 
46
- File.write(args.first, plugin.parlour.rbi)
88
+ File.write(args.first, plugin.parlour.send(generator_method))
47
89
  end
48
90
  end