AaronC81 / sord

Convert YARD docs to Sorbet RBI and Ruby 3/Steep RBS files
https://sord.aaronc.cc
MIT License
299 stars 18 forks source link

sord does not detect duck type signatures that contain symbol characters #151

Closed postmodern closed 2 years ago

postmodern commented 2 years ago

Describe the bug

I noticed that sort-4.0.0 can successfully recognize duck-type signatures such as #foo or #to_s, but thinks duck-type signatures such as #=== or #foo! are not types.

To Reproduce

Gemfile:

source 'https://rubygems.org'

gem 'sord', require: false

lib/test.rb:

module Test
  #
  # @param [#foo] arg1
  #
  # @param [#===] arg2
  #
  # @param [#foo!] arg3
  #
  # @return [Object]
  #
  def self.test(arg1,arg2,arg3)
  end
end
$ bundle install
$ bundle exec sord defs.rbi

Expected behavior

Recognizes #=== and #foo!.

Actual behavior

$ be sord defs.rbi
[INFER] Assuming from filename you wish to generate in RBI format
[INFO ] Running YARD...
[warn]: Could not load default RDoc formatter, ignoring any markup (install RDoc to get default formatting).
Files:           1
Modules:         1 (    1 undocumented)
Classes:         0 (    0 undocumented)
Constants:       0 (    0 undocumented)
Attributes:      0 (    0 undocumented)
Methods:         1 (    0 undocumented)
 50.00% documented
[DUCK ] (Test.test) #foo looks like a duck type, replacing with untyped
[WARN ] (Test.test) "#===" does not appear to be a type
[WARN ] (Test.test) "#foo!" does not appear to be a type
[DONE ] Processed 2 objects (1 namespaces and 1 methods)
[WARN ] There were 2 important warnings in the output file, listed below.
[WARN ] The types which caused them have been replaced with SORD_ERROR_ constants.
[WARN ] Please edit the file to fix these errors.
[WARN ] Alternatively, edit your YARD documentation so that your types are valid and re-run Sord.
        (Test.test) "#===" does not appear to be a type
        (Test.test) "#foo!" does not appear to be a type

Additional information

AaronC81 commented 2 years ago

Good spot, cheers!

153 should fix this - I've verified that it produces untyped rather than a SORD_ERROR for the constructors taking #[] on your Ronin::Support::Binary::CTypes::OS definitions, which I imagine is where you saw this!