Closed bradfeehan closed 1 year ago
This implements the fix suggested by @akimd here:
I believe the proper fix is in lib/yard/parser/ruby/ast_node.rb to replace: def line line_range && line_range.first end by def line line_range && line_range.begin end since begin always returns the "first" element, as nil if it does not exist (while first dies if begin is nil). However in that case yardoc dies farther: /opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ruby_parser.rb:624:in `block in insert_comments': undefined method `-' for nil:NilClass (NoMethodError) ((node.line - 1).downto(node.line - 2).to_a + [node.line]).each do |line| ^ from /opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ast_node.rb:212:in `traverse' from /opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ruby_parser.rb:615:in `insert_comments' so it looks like after all it does not like line to return nil, contrary to what the && seems to imply. So I made it def line line_range && line_range.begin || 1 end and this time yardoc finishes properly.
I believe the proper fix is in lib/yard/parser/ruby/ast_node.rb to replace:
def line line_range && line_range.first end
by
def line line_range && line_range.begin end
since begin always returns the "first" element, as nil if it does not exist (while first dies if begin is nil).
However in that case yardoc dies farther:
/opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ruby_parser.rb:624:in `block in insert_comments': undefined method `-' for nil:NilClass (NoMethodError) ((node.line - 1).downto(node.line - 2).to_a + [node.line]).each do |line| ^ from /opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ast_node.rb:212:in `traverse' from /opt/local/lib/ruby3.1/gems/3.1.0/gems/yard-0.9.27/lib/yard/parser/ruby/ruby_parser.rb:615:in `insert_comments'
so it looks like after all it does not like line to return nil, contrary to what the && seems to imply. So I made it
def line line_range && line_range.begin || 1 end
and this time yardoc finishes properly.
Fixes lsegal/yard#1434.
Describe your pull request and problem statement here.
bundle exec rake
Description
This implements the fix suggested by @akimd here:
Fixes lsegal/yard#1434.
Describe your pull request and problem statement here.
Completed Tasks
bundle exec rake
locally (if code is attached to PR).