Shopify / Shopify/tapioca

Add a DSL generator for requiring the right ancestors in helpers

Open
#621 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Because view helpers are dynamically included by Rails, Sorbet is not aware that the modules will be included into certain classes. We can solve this by generating RBIs that add the right requires_ancestor to each helper.

There are two possible behaviors outlined in the Rails documentation for include_all_helpers.

If include_all_helpers is turned on, then every helper is included into ActionView::Base. If not, then application_helper is the only one included into ActionView::Base and every other gets included only in the controller views they match with (e.g.: UsersHelper gets included only in views from UsersController, but not into views from other controllers).

Because Rails loads every module ending in Helper as a helper module, I suspect the DSL generator can just filter all_modules based on whether their name ends with Helper or not and then produce an RBI that looks like this (depending on the value of the configuration, which may alter the requires_ancestor statement).

# users_helper.rbi
# When include_all_helpers is turned on
module UsersHelper
  requires_ancestor { ActionView::Base }
end


# When include_all_helpers is turned off
module UsersHelper
  requires_ancestor { ??? } # Not sure if it would be UsersController or some internal Rails class
end

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.

Research direction

Start with the Rails documentation for include_all_helpers and the DSL generator's all_modules filtering described in the issue. Determine the correct requires_ancestor target for helpers when the option is enabled and disabled, including the UsersHelper and UsersController relationship. Done means the generator emits the appropriate RBI for each configuration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.