lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.95k stars 398 forks source link

Nasty problem upgrading to 0.9.28 #1465

Open mcorino opened 2 years ago

mcorino commented 2 years ago

I am documenting a native C-Ruby extension with files much like this:

# -----------------
# - Just comment
# -----------------

module Top

  # Test class
  #
  class Test < Object

    # @!method test(*args)
    # @overload test(i, b)
    #   @param i [Integer] an integer
    #   @param b [Boolean] a boolean
    # @overload test(s='')
    #   @param s [String] a string
    #
    #   Method with overloads

    # @!method ::new
    #   default constructor

  end

end

This worked just fine with Ruby 2.5 and yard 0.9.12 but since I upgraded to Ruby 3.1.2 and yard 0.9.28 I have a nasty problem with the generated documentation in that ALL methods of classes like class Test above are generated as members of the module Top instead of class Test.

Weirdly I found that when the class declaration contains any non-commented statement like:

module Top

  # Test class
  #
  class Test

    # ...

    self
  end

end

the documentation gets generated correctly. This is however a workaround I would be not happy about to have to apply.

Steps to reproduce

This is the minimal reproduction for the issue. I've done my best to remove all extraneous code and unique environment state on my machine before providing these steps:

  1. Save the example above to some file
  2. Run the following command: yardoc <file>
  3. Open browser to the generated index.html file
  4. Click on the 'Top' module link.
  5. Click on the 'Test' class link

Actual Output

Methods listed under top module.

Expected Output

Methods listed under class where thery are documented.

Environment details:

I have read the Contributing Guide.