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

add basic devise annotation #180

Merged
merged 10 commits into from
Nov 24, 2023

Conversation

fcheung
Copy link
Contributor

@fcheung fcheung commented Oct 21, 2023

Type of Change

  • [ x ] Add RBI for a new gem
  • Modify RBI for an existing gem
  • Other:

Changes

This adds some very basic annotations for devise. Prior to tapioca 0.11.8 tapioca would generate rbis for Devise::SessionsController, Devise::RegistrationsController etc. (so that it could define helper related modules on them). As of tapioca 0.11.9 this is no longer the case, so subclasses of devise controllers cause a sorbet error whatever the type checking level requested on those files since the parent class is not known to sorbet.

I also added the actions for each controllers and the core devise controller methods

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.

@fcheung
Copy link
Contributor Author

fcheung commented Oct 23, 2023

I've added an index entry (and fixed a few more bits), but the runtime checks now fail

Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:3:0-36:3)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:7:2-7:19)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:11:2-11:24)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:14:2-14:21)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:18:2-18:25)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:22:2-22:29)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:26:2-26:25)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:29:2-29:31)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:32:2-32:26)
Error: Missing runtime constant ::DeviseController (defined at rbi/annotations/devise.rbi:35:2-35:28)
Error: Missing runtime constant ::Devise::ConfirmationsController (defined at rbi/annotations/devise.rbi:38:0-47:3)
Error: Missing runtime constant ::Devise::ConfirmationsController (defined at rbi/annotations/devise.rbi:40:2-40:14)
Error: Missing runtime constant ::Devise::ConfirmationsController (defined at rbi/annotations/devise.rbi:43:2-43:17)
Error: Missing runtime constant ::Devise::ConfirmationsController (defined at rbi/annotations/devise.rbi:46:2-46:15)
Error: Missing runtime constant ::Devise::PasswordsController (defined at rbi/annotations/devise.rbi:49:0-65:3)
Error: Missing runtime constant ::Devise::PasswordsController (defined at rbi/annotations/devise.rbi:52:2-52:14)
Error: Missing runtime constant ::Devise::PasswordsController (defined at rbi/annotations/devise.rbi:56:2-56:17)
Error: Missing runtime constant ::Devise::PasswordsController (defined at rbi/annotations/devise.rbi:60:2-60:15)
Error: Missing runtime constant ::Devise::PasswordsController (defined at rbi/annotations/devise.rbi:64:2-64:17)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:67:0-96:3)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:69:2-69:14)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:73:2-73:17)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:77:2-77:15)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:83:2-83:17)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:87:2-87:18)
Error: Missing runtime constant ::Devise::RegistrationsController (defined at rbi/annotations/devise.rbi:95:2-95:17)
Error: Missing runtime constant ::Devise::SessionsController (defined at rbi/annotations/devise.rbi:98:0-114:3)
Error: Missing runtime constant ::Devise::SessionsController (defined at rbi/annotations/devise.rbi:101:2-101:14)
Error: Missing runtime constant ::Devise::SessionsController (defined at rbi/annotations/devise.rbi:105:2-105:17)
Error: Missing runtime constant ::Devise::SessionsController (defined at rbi/annotations/devise.rbi:109:2-109:18)
Error: Missing runtime constant ::Devise::SessionsController (defined at rbi/annotations/devise.rbi:113:2-113:25)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:116:0-138:3)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:119:2-119:14)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:123:2-123:17)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:127:2-127:15)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:133:2-133:63)
Error: Missing runtime constant ::Devise::UnlocksController (defined at rbi/annotations/devise.rbi:137:2-137:42)

DeviseController is a bit of a weird one since your application config sets what its parent class is ( https://github.com/heartcombo/devise/blob/main/app/controllers/devise_controller.rb#L4 )

Plus the devise controllers are expected to be loaded by rails so they're not on the load path. I had a lock at the other index entries, but none of the other ones have engine-y things like this

@KaanOzkan
Copy link
Contributor

If it's not possible to require the files that define these you could add a @shim: description tag on top of the constant definitions so that they aren't checked in runtime:

# @shim: this is included at runtime https://github.com/rails/globalid/blob/v1.0.0/lib/global_id/railtie.rb#L38

@DougEdey
Copy link

DougEdey commented Nov 9, 2023

Hello! Is there any progress on this? After updating tapioca I'm encountering the same issue as Shopify/tapioca#1692

@KaanOzkan
Copy link
Contributor

@fcheung I rebased your branch on latest main to utilize #187 which is needed for marking classes as shims.

@KaanOzkan
Copy link
Contributor

I haven't tested the signatures themselves because we don't use devise in the repos we own but I assume this was tested in your application.

@KaanOzkan KaanOzkan merged commit c141a6c into Shopify:main Nov 24, 2023
2 checks passed
@fcheung
Copy link
Contributor Author

fcheung commented Nov 24, 2023

Amazing - thanks!

@Morriar Morriar added the rbi Change related to RBI annotations label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rbi Change related to RBI annotations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants