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

Inline sorbet mode #167

Open
dduugg opened this issue May 2, 2023 · 0 comments
Open

Inline sorbet mode #167

dduugg opened this issue May 2, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@dduugg
Copy link

dduugg commented May 2, 2023

Is your feature request related to a problem? Please describe.
I would like an option to place Sorbet sigs in the source file, rather than a separate .rbi file, to make use of the sorbet-runtime.

Describe the solution you'd like
To use the example in the README, given:

module Example
  class Person
    # @param name [String] The name of the Person to create.
    # @param age [Integer] The age of the Person to create.
    # @return [Example::Person]
    def initialize(name, age)
      @name = name
      @age = age
    end

    # @return [String]
    attr_accessor :name

    # @return [Integer]
    attr_accessor :age

    # @param possible_names [Array<String>] An array of potential names to choose from.
    # @param possible_ages [Array<Integer>] An array of potential ages to choose from.
    # @return [Example::Person]
    def self.construct_randomly(possible_names, possible_ages)
      Person.new(possible_names.sample, possible_ages.sample)
    end
  end
end

I would like to be able to transform the file into:

module Example
  class Person
    # @param name The name of the Person to create.
    # @param age The age of the Person to create.
    sig { params(name: String, age: Integer).void }
    def initialize(name, age)
      @name = name
      @age = age
    end

    sig { returns(String) }
    attr_accessor :name

    sig { returns(Integer) }
    attr_accessor :age

    # @param possible_names An array of potential names to choose from.
    # @param possible_ages An array of potential ages to choose from.
    sig { params(possible_names: T::Array[String], possible_ages: T::Array[Integer]).returns(Example::Person) }
    def self.construct_randomly(possible_names, possible_ages)
      Person.new(possible_names.sample, possible_ages.sample)
    end
  end
end

Note that I've kept the docstrings, and only scrubbed the types from the YARD annotations, bc the yard-sorbet plugin can merge the two when generating YARD docs.

@dduugg dduugg added the enhancement New feature or request label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant