Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix error when docsting is just only @option #1515

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

ksss
Copy link
Contributor

@ksss ksss commented Oct 9, 2023

Description

Running yardoc on the following Ruby code will result in an error.

# t.rb
class Foo
  # @option
  def m
  end
end
$ bin/yardoc t.rb
[error]: Unhandled exception in YARD::Handlers::Ruby::MethodHandler:
  in `t.rb`:3:

	3: def m

[error]: NoMethodError: undefined method `length' for nil:NilClass
[error]: Stack trace:
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/default_factory.rb:147:in `extract_types_and_name_from_text_unstripped'
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/default_factory.rb:130:in `extract_types_and_name_from_text'
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/default_factory.rb:79:in `parse_tag_with_types_name_and_default'
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/default_factory.rb:91:in `parse_tag_with_options'
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/library.rb:237:in `send_to_factory'
	/Users/yuki.kurihara/src/github.com/ksss/yard/lib/yard/tags/library.rb:169:in `option_tag'

This problem is seen only with @option and not with other major tags.

I presume that this is probably due to the fact that if text is "" in the following code, the result will be [], creating a text == nil condition when retrieved.

text.strip.split(/\s+/, 2)

If the Docstring is only "@param", text is still "".
To correct the problem, I now treat text as "" when it is nil.

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).

@lsegal lsegal merged commit dd01e86 into lsegal:main Aug 26, 2024
25 checks passed
@lsegal
Copy link
Owner

lsegal commented Aug 26, 2024

Sorry for the delay, but thank you for the contribution!

@ksss ksss deleted the fix-docsting-parse-error branch August 26, 2024 14:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants