rdoc icon indicating copy to clipboard operation
rdoc copied to clipboard

Handle ghost methods followed by undocumented methods

Open p8 opened this issue 1 year ago • 2 comments

Docs for ghost methods would get thrown away if the following method does not have a comment. By parsing comments on linebreaks we avoid this problem.

Builds on: #1258

p8 avatar Dec 29 '24 13:12 p8

This approach changes the way to write metaprogramming comment. Example in https://ruby.github.io/rdoc/RDoc/Parser/Ruby.html#class-RDoc::Parser::Ruby-label-Metaprogrammed+Methods indicates that newline between metaprogramming comment and metaprogramming code is allowed, and this pull request changes it.

# This is OK
class ActiveStorage::Blob < ActiveStorage::Record
  ##
  # :method:
  #
  # Returns the associated ActiveStorage::Attachment instances.
  has_many :attachments, autosave: false
end

# OK in master, but document is not generated with this pull request
class ActiveStorage::Blob < ActiveStorage::Record
  ##
  # :method:
  #
  # Newline between metaprogramming comment and metaprogramming code

  has_many :attachments, autosave: false
end

The problem is in the RDoc notation ambiguity. ghost_method+undocumented_method and metaprogramming_comment+metaprogramming_code are ambiguous. I found a workaround in rails/rails by inserting ## https://github.com/rails/rails/blob/be9aa73dd72f1097be5d45a58d7912447a266bd1/activemodel/lib/active_model/attributes.rb#L90

##
# :method: ghost

##
private # this is not a metaprogramming code

Disallow newline is one possible approach but is a big change that need to be carefully considered. Another possible approach is to disallow some specific pattern like def [different_name], private, public etc. Or don't change and just document the workaround.

tompng avatar Jan 02 '25 20:01 tompng

Thanks for the explanation @tompng ! I'll try to add a test to document this behaviour.

p8 avatar Jan 03 '25 15:01 p8