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

Fix HelperMethods definitions #1611

Merged
merged 3 commits into from
Aug 21, 2023
Merged

Conversation

jhawthorn
Copy link
Contributor

This fixes two problems with the ActionControllerHelpers compiler:

First is that this previously didn't gather abstract controllers. This broke for us because we have an abstract ApplicationController, and subclasses of that (all of our controllers) may then generate include ApplicationController::HelperMethods which sorbet then can't find. This PR re-includes abstract controllers, I don't see any reason not to include them, but maybe I've missed something.

Second this avoids generating HelperMethods for controllers which are only inheriting. Since Rails 6.1, when a controller has identical helpers to its superclass Rails will not generate a new HelperMethods module. We should do the same to avoid defining modules which do not actually exist, both because it's incorrect (pretty mildly incorrect, it pretends a constant exists where one doesn't, but the same constant with the same values exists in the superclass) but also it generates a lot of unnecessary files (which I think is the same motivation as #1299).

I'm new to tapioca/sorbet so please let me know if I've missed something 😅.

Helpers methods are generated for abstract controllers, and then are
inherted by children, so we should be gathering them.

In the added test the generated RBI for UserController references
::ApplicationController::HelperMethods.
Since Rails 6.1, when a controller has identical helpers to its
superclass Rails will not generate a new HelperMethods modules (which
saves significant memory).

We should do the same to avoid declaring modules which don't actually
exist in reality, this also avoids a lot of unnecesary generated RBI
files which use helper/helper_methods appropriately sparingly.
@jhawthorn jhawthorn requested a review from a team as a code owner August 17, 2023 01:28
@jhawthorn
Copy link
Contributor Author

I have signed the CLA!

Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you!

Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Did a quick test on our monolith with @bitwise-aiden.

@KaanOzkan KaanOzkan merged commit f3e2850 into Shopify:main Aug 21, 2023
@shopify-shipit shopify-shipit bot temporarily deployed to production September 13, 2023 22:55 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants