Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when @option with non-method #1508

Merged
merged 1 commit into from
Sep 30, 2023
Merged

Conversation

ksss
Copy link
Contributor

@ksss ksss commented Sep 19, 2023

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

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

Copy link
Owner

@lsegal lsegal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR-- I think one of the concerns is that other custom non method CodeObjects might support option tags, and if so, should function. The requirement here is more duck-typey than strictly object type, specifically that they must implement object.parameters.

@@ -1,4 +1,4 @@
<% if object.has_tag?(:option) %>
<% if object.has_tag?(:option) && object.type == :method %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as a respond_to?(:parameters) check, since other (custom) types might support option tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'll fix later.

@ksss ksss force-pushed the non-method-option branch from 1c3de4e to 3a64f88 Compare September 30, 2023 13:35
@lsegal lsegal merged commit 2d197a3 into lsegal:main Sep 30, 2023
25 checks passed
@lsegal
Copy link
Owner

lsegal commented Sep 30, 2023

Appreciate the changes and thank you for this fix!

@ksss ksss deleted the non-method-option branch October 1, 2023 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants