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

Include an auto-generated RBI file when publishing the gem #1854

Closed
connorshea opened this issue Dec 5, 2019 · 1 comment
Closed

Include an auto-generated RBI file when publishing the gem #1854

connorshea opened this issue Dec 5, 2019 · 1 comment

Comments

@connorshea
Copy link
Member

Is your feature request related to a problem? Please describe.
I'd like to have a Sorbet RBI file included in Faker by default.

RBI files are type definition files, similar to .d.ts files in TypeScript.

They look like this:

class Faker
  class Base
    class HalfLife < Faker::Base
      # Produces the name of a location from the Half-Life games.
      # 
      # ```ruby
      # Faker::Games::HalfLife.location #=> "Black Mesa Research Facility"
      # ```
      sig { returns(::String) }
      def self.location; end
    end
  end
end

And if you use Sorbet in your project and have the VS Code extension, you can get these types and docs in your editor like so:

Screen Shot 2019-12-04 at 9 46 31 PM

We can use Sord to generate them automatically from the YARD docs we've been creating.

As a proof of concept, I created this gist with instructions for creating a full RBI using Sord (it requires using Sord master + two of my PRs to it, which should be merged soon, as well as Faker w/ #1853 merged in). These instructions could be made into a Rake task so they'd be an automated part of the release process.

The file would be kept at rbis/faker.rbi and wouldn't effect anyone that wasn't using Sorbet. It'd effectively be invisible to most end-users.

If you're adding new objects, please describe how you would use them

I'd use them to get typechecking in, validate that the YARD docs are correct (e.g. if one of our methods says it returns a String but I'm using it in my project like an Integer, then Sorbet will catch that and the typecheck will fail. This'd either mean that the YARD doc is wrong or I'm doing something dumb).

Describe alternatives you've considered

The main alternatives are:

  • I generate the RBI for myself and just use it in my project without needing to share it with anyone else. This is fine, but it seems rather selfish. :P
  • Use sorbet-typed to distribute the, this requires us to update the sorbet-typed definitions every time the gem receives an update.

I'd be fine with sorbet-typed as a solution if we don't want to maintain it in this repo, but I'd like to use Faker as a test to see if this is a viable thing others could do :)

Additional context

@thdaraujo
Copy link
Contributor

Hey, folks. In an effort to lighten our load as maintainers and be able to serve you better in the future, the faker-ruby team is working on cleaning out the cobwebs in this repo by pruning the backlog. As there are few of us, there are a lot of items that will simply never earn our attention in a reasonable time frame, and rather than giving you an empty promise, we think it makes more sense to focus on more recent issues. That means, unfortunately, that we must close this issue.

Don't take this the wrong way: our aim is not to diminish the effort people have made or dismiss problems that have been raised. If you feel that we should reopen this issue, then please let us know so that we can reprioritize it. Thanks!

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

No branches or pull requests

2 participants