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

Question: No support for private attr_* syntax? #1471

Open
shu-i-chi opened this issue Dec 29, 2022 · 1 comment
Open

Question: No support for private attr_* syntax? #1471

shu-i-chi opened this issue Dec 29, 2022 · 1 comment

Comments

@shu-i-chi
Copy link

Does YARD not support private attr_* syntax?

With a private attr_* syntax introduced in Ruby 3.0 (https://bugs.ruby-lang.org/issues/17314);

class Sample
  private attr_reader :documented_private_foo
end

yard doc displays a warning message;

yard doc
[warn]: in YARD::Handlers::ruby::VisibilityHandler: Undocumentable statement, cannot determine method name
        in file 'lib/sample.rb':two:

        2: private attr_reader :documented_private_foo

and private attributes defined with the syntax are inappropriately documented:

yard-document-with-private-attr-syntax

Steps to reproduce

  1. Make Gemfile and lib/sample.rb:

    • Gemfile

      # frozen_string_literal: true
      
      source "https://rubygems.org"
      
      # # Uncomment with Ruby 3.0.5 x Bundler 2.2.33.
      # git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
      
      gem "yard", "0.9.28"
      
    • lib/sample.rb

      class Sample
        # NG: private attr_* syntax introduced in Ruby 3.0
        private attr_reader :documented_private_foo # inappropriately documented
      
        # OK: conventional way (only {Sample#public_bar} is documented)
        attr_reader :private_bar, :public_bar
        private :private_bar
      end
  2. Run the following command to generate documents and to open a server.

    bundle install
    
    bundle exec yard doc && bundle exec yard server
  3. Open browser to http://localhost:8808/docs/Sample.

Environment details

  • OS: Ubuntu 20.02 (WSL2)

  • Ruby version (ruby -v):

    • ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
    • ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [x86_64-linux]
  • YARD version (bundle exec yard -v): yard 0.9.28

  • Relevant software dependency/versions:

    • Bundler (bundle version):

      • Bundler version 2.3.26 (2022-12-29 commit unknown) (Ruby 3.1.3)
      • Bundler version 2.2.33 (2022-12-29 commit unknown) (Ruby 3.0.5)
    • Ruby are installed via rbenv 1.2.0-14-gc6cc0a1.

I have read the Contributing Guide.

@lsegal
Copy link
Owner

lsegal commented Apr 8, 2023

Sorry for the late reply on this, but yes, YARD does not quite support arbitrary visibility modifier prefixes quite yet. It's a little difficult to implement this (though not impossible) because of the informality of what can be used as a method declaration modifier, as well as, to some degree, the order of modifiers.

The presumption would be to special case public/private/protected, though this would likely be an incomplete implementation. This is, however, what we do for methods, and would need to be ported over to work for attributes.

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

No branches or pull requests

2 participants