yard icon indicating copy to clipboard operation
yard copied to clipboard

Indication to identify protected and private methods

Open noraj opened this issue 4 years ago • 6 comments

--protected and --private of yard doc show protected and private methods on the documentation. But once you have enabled them, you have public, protected and privates methods all mixed without a way to know which is what. It would be nice to have a little badge next to protected and private methods to allow to identify them.

Expected result

Something like that

image

image

noraj avatar Feb 24 '21 14:02 noraj

It doesn't seem like your methods are correctly being detected as private/protected, YARD should already be showing these tags. This is the output for the following minimal repro:

class A
  protected

  def a; end
  def b; end

  private

  def c; end
  def d; end
end

image

lsegal avatar Feb 24 '21 19:02 lsegal

Yes I can see the CSS public class set on each <li>. I also see that without --protected or --private my method still appears in yard. I didn't use the following syntax:

class A
  protected

  def a; end
  def b; end

  private

  def c; end
  def d; end
end

but instead this one:

class A
  def a; end
  def b; end
  def c; end
  def d; end

  protected :a, :b
  private :c, :d
end

Which is valid ruby and totally works as expected

image

Also I don't know if it matters but I'm in class << self because class << self + private is similar to private_class_method and I saw there #1162 yard had issues with inline private_class_method but you said as a workaround that private_class_method was working with yard if used in a separate line. this may be different and #1162 is from 2018 but I mention it as it may lead somewhere.

So I have

class A

  class << self
    def a; end
    def b; end
    def c; end
    def d; end

    protected :a, :b
    private :c, :d
  end
end

noraj avatar Feb 25 '21 09:02 noraj

I just tried

class A

  class << self
    def a; end
    def b; end

    protected

    def c; end
    def d; end
  end
end

Only a & b are show (which confirms that the alternative syntax shown earlier is not supported by yard) but even using the "classic" syntax seems to be bugged inside class methods but adding --protected never show the methods c & d.

It seems that whatever the syntax is potected_class_method or class << self + "section" protected or class << self + protected c:, d: yard has an issue with class methods that doesn't appears with instance methods.

Now if I tried to add the visibility and scope tags as a workaround, it hides the method even when --protected is provided to yard doc.

    # @!scope class
    # @!visibility protected

noraj avatar Feb 25 '21 09:02 noraj

I'm digging some old maybe related issues #847, #760, #551 (I stopped after because it was getting too old)

noraj avatar Feb 25 '21 09:02 noraj

I'll me my repository public soon so you can see the real code.

noraj avatar Mar 02 '21 14:03 noraj

Source: https://github.com/sec-it/pass-station Yard doc: https://sec-it.github.io/pass-station/yard/PassStation.html

@lsegal I can confirms that protected badge is displayed only for instance methods and not for class methods.

noraj avatar Mar 08 '21 18:03 noraj