Sorbet: Support `:require: false` gems in Gemfile

Created on 27 Jun 2019  路  5Comments  路  Source: sorbet/sorbet

Problem

Some dependencies listed in a project's Gemfile do not need to have rbis generated for them. For example, rubocop can be run during development, and not relied on as a library from within a project.

Proposed solution

Make sorbet sensitive to a :sorbet_ignore Gemfile group. This would allow users to control which gems are provided to sorbet.

source 'https://rubygems.org'
gem 'cantor'
gem 'sorbet', :group => :development
gem 'sorbet-runtime'

group :sorbet_ignore do
  gem 'rubocop'
end

Additional info

Through some experimentation, modifying the sites where we call Bundler.load to first run:

Bundler.settings.set_command_option :without, [:sorbet_ignore]

causes gems in the :sorbet_ignore section to no longer show up in the spec set.

enhancement

Most helpful comment

Usually rubocop is on the gemfile entry as gem 'rubocop', require: false since you don't need, and usually don't want to load rubocop in your application. How about sorbet respecting the :require option?

All 5 comments

Would this be something that can be specified in the sorbet folder somehow, either passed as a command line option or specified in the sorbet/config? I don't love the idea of modifying my Gemfile to simply support the srb init which will really only be run once or very infrequently.

Usually rubocop is on the gemfile entry as gem 'rubocop', require: false since you don't need, and usually don't want to load rubocop in your application. How about sorbet respecting the :require option?

+1 to using require: false for this

require: false sounds good to me.

I am not 100% sure if I followed the expectations in this issue correctly, but it seems that sorbet is already respecting require: false since this commit was merged: https://github.com/sorbet/sorbet/commit/6dccbfa886b3031b6df618335da6be8f62b09c02#diff-fc7ece157e1d959d151e970fb52e9747R557

Was this page helpful?
0 / 5 - 0 ratings