-
-
Notifications
You must be signed in to change notification settings - Fork 398
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 double return tag. #1226
Fix double return tag. #1226
Conversation
@@ -213,6 +213,7 @@ | |||
foo = Registry.at('Foo#foo?') | |||
expect(foo.docstring).to eq 'DOCSTRING' | |||
expect(foo.tag(:return).types).to eq ['Boolean'] | |||
expect(foo.tags(:return).size).to eq 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fix to handler_methods.rb
this test still passed. And I don't quite understand why. I would have expected this to yield 2 and fail when YARD added an extra @return
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no extra tags on the method defined in this specific test, which would explain why the result hasn't changed.
@@ -226,6 +227,7 @@ | |||
eof | |||
foo = Registry.at('Foo#foo?') | |||
expect(foo.tag(:return).types).to eq ['String'] | |||
expect(foo.tags(:return).size).to eq 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test that catches the bug. I can dig deeper into why the other test didn't raise any errors before the fix.
@@ -67,7 +67,9 @@ def handle_method(scope, var_name, name, func_name, _source_file = nil) | |||
register_visibility(obj, visibility) | |||
find_method_body(obj, func_name) | |||
obj.explicit = true | |||
obj.add_tag(Tags::Tag.new(:return, '', 'Boolean')) if name =~ /\?$/ | |||
if name =~ /\?$/ && obj.tags(:return).empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation should probably be normalized to handle overloads as per the Ruby handler:
https://github.com/lsegal/yard/blob/master/lib/yard/handlers/ruby/method_handler.rb#L41-L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any existing patterns to sharing logic between Ruby and C handlers?
Or should I just copy+paste?
I took another stab at this. Added a I'll squash it if you are ok with these changes. |
0b1f946
to
4bb63b3
Compare
@@ -0,0 +1,18 @@ | |||
# frozen_string_literal: true | |||
# Shared functionality between Ruby and C method handlers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this will add a docstring to the YARD::Handlers
module, not MethodHandler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will also want at least one newline after the frozen directive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good minus the docstring issue.
4bb63b3
to
0a7b04e
Compare
0a7b04e
to
bc94da3
Compare
I corrected the docstring and rebased to latest YARD master branch. |
Great thanks for your work on this! |
Description
In our C/C++ code base where we implement Ruby functions we some times have explicit
@return [Boolean]
tags for predicate methods.YARD is adding an extra
@return [Boolean]
regardless if there already is one.See output: http://ruby.sketchup.com/Geom/BoundingBox.html#contains%3F-instance_method
Completed Tasks
bundle exec rake
locally (if code is attached to PR).