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

Handle ghost methods followed by undocumented methods #1261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

p8
Copy link
Contributor

@p8 p8 commented Dec 29, 2024

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 added 2 commits December 29, 2024 12:56
`:on_nl`, `:on_ignored_nl`, `:on_comment`, `:on_embdoc` are handled by a
single `when` branch. In this branch there are multiple `if` branches
handling `:on_nl` and `:on_ignored_nl` separately from `:on_comment` and
`:on_embdoc`.

By having separate `when` branches for `:on_nl`/`:on_ignored_nl` and
`:on_comment`/`:on_embdoc` we can remove the `if` statements.
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.
@tompng
Copy link
Member

tompng commented Jan 2, 2025

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.

@p8
Copy link
Contributor Author

p8 commented Jan 3, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants