`tapioca gem` misses sig for module_function methods of the class variety

Open
#2,000 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
tooling

Research direction

Reproduce the generated sorbet/rbi/gems/code_ownership@1.37.0.rbi output with tapioca gem code_ownership, using the code_ownership.rb module_function example. Trace Tapioca's gem RBI generation and compare it with the rbi gem's parsing behavior; done means the generated RBI retains the signature for both the instance and singleton method, or uses module_function as shown.

Written by the indexing model from the issue text.

Description

help-wanted

When generating sorbet/rbi/gems/code_ownership@1.37.0.rbi with tapioca gem code_ownership module_function defined methods will be created without signatures.

# Gemfile
source "https://rubygems.org"

gem 'tapioca', require: false, :group => [:development, :test]
gem "code_ownership", "1.37.0"

Specifically

# code_ownership.rb

module CodeOwnership
  module_function
  sig { params(klass: T.nilable(T.any(::Module, T::Class[T.anything]))).returns(T.nilable(::CodeTeams::Team)) }
  def for_class(klass); end
end

will be turned into

# code_ownership.rbi

module CodeOwnership
  sig { params(klass: T.nilable(T.any(::Module, T::Class[T.anything]))).returns(T.nilable(::CodeTeams::Team)) }; def for_class(klass); end

  class << self
    def for_class(klass); end
  end
end

should be turned into

# code_ownership.rbi

module CodeOwnership
  sig { params(klass: T.nilable(T.any(::Module, T::Class[T.anything]))).returns(T.nilable(::CodeTeams::Team)); def for_class(klass); end

  class << self
    sig { params(klass: T.nilable(T.any(::Module, T::Class[T.anything]))).returns(T.nilable(::CodeTeams::Team)) }; def for_class(klass); end
  end
end

OR

# code_ownership.rbi

module CodeOwnership
  module_function
  sig { params(klass: T.nilable(T.any(::Module, T::Class[T.anything]))).returns(T.nilable(::CodeTeams::Team)) }; def for_class(klass); end
end

I tried testing this in the rbi gem but it correctly parsed the module to the last one above

I'll gladly dive into the code to fix this if somebody could point out where this is an issue. I did some code diving as you can see already but I'm a bit lost where

Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Shopify/tapioca

All issues in Shopify/tapioca

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.