Shopify / packwerk

Good things come in small packages.
MIT License
1.65k stars 113 forks source link

[Feature Request] YARD support as method interface #383

Closed euglena1215 closed 7 months ago

euglena1215 commented 11 months ago

Suggestion

Support YARD as well as Sorbet as a method interface.

Details

I expect the following behavior.

# packs/foo/app/models/foo.rb
class Foo
  # @return [Bar]
  def bar
    self.bar
  end
end
# packs/bar/app/models/bar.rb
class Bar
end

As shown above, if a comment is placed in the bar method that can be interpreted as YARD to the Foo class, then the Foo class is handled as dependent on the Bar class.

Motivation

In our Rails application we use packwerk and use YARD to define types instead of sorbet. (To be more precise, we use the sord gem to generate RBS from YARD to utilize type information in our editor and IDE).

I understand that you are recommending the use of Sorbet. However, if you support YARD, we can use packwerk more effectively. I also expect that there are many Rails applications out there that do not use Sorbet, but use YARD. I think YARD support will lower the barrier to using packwerk.

exterm commented 11 months ago

Just a note that there's no explicit support for sorbet in packwerk. It "just works" since sorbet signatures are just Ruby code and use constant references. It's a lucky coincidence.

So there's no pre-existing method interface parsing mechanism that we can just add YARD to.

I do agree though that YARD support would be useful.

alexevanczuk commented 11 months ago

There are some efforts underway to allow for client configured parsers: https://github.com/Shopify/packwerk/pull/375

This would permit a plugin to parse classes declared in YARD comments.

Besides that though I agree it'd make sense to permit YARD comments to be parsed this way (regardless if it's implemented in packwerk itself or as a community maintained plugin in packwerk-extensions)!

euglena1215 commented 11 months ago

Thank you for the information!

There are some efforts underway to allow for client configured parsers: https://github.com/Shopify/packwerk/pull/375

I look forward to waiting for that PR to be merged.

I will try to create a packwerk-yard gem with https://github.com/richardmarbach/packwerk-haml as a reference.

euglena1215 commented 11 months ago

I am creating https://github.com/euglena1215/packwerk-yard.

I found something in the original pull request that needs to be fixed in the process of making it, so I commented on it. https://github.com/Shopify/packwerk/pull/375#issuecomment-1879508382

rafaelfranca commented 7 months ago

Thank you for the issue but we have no interest in parsing YARD in this tool.