lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.92k stars 394 forks source link

Fix error when `@option` with non-method #1508

Closed ksss closed 9 months ago

ksss commented 9 months ago

Description

Applying the @option tag to non-method code results in an error during documentation generation.

$ cat t.rb
# @option [String] foo bar
module Foo
end

$ bundle exec yardoc t.rb
[error]: Exception occurred while generating 'Foo.html'
[error]: NoMethodError: undefined method `parameters' for #<yardoc module Foo>
[error]: Stack trace:
    /Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/code_objects/base.rb:379:in `method_missing'
    /Users/yuki.kurihara/src/github.com/ksss/yard/templates/default/tags/html/option.erb:4:in `_erb_cache_33'
    /Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/templates/template.rb:289:in `erb'
    /Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/templates/template.rb:371:in `render_section'
    /Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/templates/template.rb:261:in `block (2 levels) in run'
    /Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/templates/template.rb:258:in `each'

Files:           1
Modules:         1 (    0 undocumented)
Classes:         0 (    0 undocumented)
Constants:       0 (    0 undocumented)
Attributes:      0 (    0 undocumented)
Methods:         0 (    0 undocumented)
 100.00% documented

I have fixed it to prevent the error from occurring.

It might be acceptable to log a warning message, but for now, I've adjusted it to match the current behavior of the @param tag, which displays nothing.

Completed Tasks

lsegal commented 9 months ago

Appreciate the changes and thank you for this fix!