chanzuckerberg / sorbet-rails

A set of tools to make the Sorbet typechecker work with Ruby on Rails seamlessly.
MIT License
638 stars 81 forks source link

Disabling a builtin model plugin #401

Open Jamie5 opened 3 years ago

Jamie5 commented 3 years ago

Is there a way to disable a builtin model plugin?

The use case is to disable active_record_named_scope, because I want to define my own with more specific parameters, but simply adding a rbi file with the desired definition results in Method XYZ.the_scope redefined with argument args as a splat argument https://srb.help/4010.

I tried putting the following in config/initializers/sorbet_rails.rb but it did not appear to work.

SorbetRails.configure do |config|
  config.enabled_model_plugins.delete(:active_record_named_scope)
end

(from what I can tell (but am not sure), there is a call to register_configured_plugins even before we run the configuration code)

Note: a workaround seems to be SorbetRails::ModelRbiFormatter.get_plugins.delete(SorbetRails::ModelPlugins::ActiveRecordNamedScope) in the config, though I guess this is undocumented and not guaranteed to work forever

hdoan741 commented 3 years ago

Thank you. I'll triage this. It does look like we call register_configured_plugins in railtie's initialize. I'll look into if we can change where this call is called to fix the bug.

For the time being, please feel free to use the workaround you've identified. Likely it'll keep working. I'll let you know if any change may affect it.