AaronC81 / sord

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

Constants without YARD @return cause errors #133

Closed wagenet closed 2 years ago

wagenet commented 2 years ago

Describe the bug

In master, constants without a YARD @return cause errors.

To Reproduce

Make a constant without a YARD @return.

Expected behavior

It treats it as untyped.

Actual behavior

[ERROR] undefined method `path' for "Organization::SYNC_INTERVAL":String
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/user_interaction.rb:364:in `method_missing'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/logging.rb:78:in `generic'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/logging.rb:152:in `omit'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:132:in `block in add_constants'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:113:in `each'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:113:in `add_constants'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:506:in `add_namespace'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:521:in `block in populate'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:521:in `each'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:521:in `populate'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/generator.rb:541:in `run'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/lib/sord/parlour_plugin.rb:70:in `generate'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/bundler/gems/sord-37961370e069/exe/sord:86:in `block (2 levels) in <top (required)>'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/command.rb:187:in `call'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/command.rb:157:in `run'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/runner.rb:444:in `run_active_command'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/runner.rb:61:in `run!'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/delegates.rb:18:in `run!'
         /Users/peterwagenet/.rvm/gems/ruby-3.0.1/gems/commander-4.6.0/lib/commander/import.rb:7:in `block in <top (required)>'

Additional information

Internally, It looks like it's expecting a special item with a path but we just have a string.

AaronC81 commented 2 years ago

Hello - thanks for giving Sord a go.

Do you have a minimal example which reproduces this issue please?

There is a test (https://github.com/AaronC81/sord/blob/master/spec/generator_spec.rb#L888) which covers the case of constants without documentation, and it seems to be passing OK on my machine and GitHub Actions:

class A
  EXAMPLE_UNTYPED_CONSTANT = 'Foo'
  # @return [String]
  EXAMPLE_TYPED_CONSTANT = 'Bar'
end

Thanks!

wagenet commented 2 years ago

I'm not sure why the example you have passes. My code is basically just this:

module Direwolf
  module Guid
    FOO = 1
  end
end
AaronC81 commented 2 years ago

Ahh, I think I got it - the exception only happens if logging to the console is enabled, which isn't the case for tests. I've fixed the problem (a constant's name being passed to logging functions, rather than the constant's YARD object), and also made log messages be unconditionally generated, even if they aren't going to be printed, so issues like this will be caught by tests.

Please could you check if #135 fixes your issue? Thanks!

wagenet commented 2 years ago

Ah, it's logging related. If you add Sord::Logging.silent = false to that spec then it fails.

wagenet commented 2 years ago

Hah, I just saw your comment. Looks like you figured this out before me!

wagenet commented 2 years ago

@AaronC81 #135 fixes it, thanks!

AaronC81 commented 2 years ago

Superb - merged :)