Sorbet: `srb rbi gems` modifies gem RBIs generated via `srb init`

Created on 30 Jun 2019  路  3Comments  路  Source: sorbet/sorbet

Input

Consider the following workflow:

  • Install sorbet into an existing ruby project that depends on a single gem ('first_gem')
  • Run srb init and commit sorbet/ folder
  • Add a new gem to your Gemfile ('second_gem') and run bundle install
  • Run srb rbi gems

My expectation, upon running srb rbi gems is that the diff would include exactly one added file, sorbet/rbi/gems/second_gem.rbi

However, srb rbi gems _also_ seems to modify the # typed: annotation in the first gem's RBI file, sorbet/rbi/gems/first_gem.rbi

I set up an example repository with a branch init-rbi-gems-issue that replicates these steps exactly (first gem: 'colored', second gem: 'timecop') in a series of commits: example repository

Specifically, you can see the modification of the original gem in the final commit.

Observed output

srb rbi gems modifies # typed: annotation level on gem RBIs created via srb init

Expected behavior

srb rbi gems should only modify gem RBIs for newly added gems or gems with changed source code (e.g. on gem version changes)


bug good first issue

Most helpful comment

Thank you for the very specific bug report! It was incredibly helpful.

In case the repo gets deleted, here's the interesting diff:

diff --git a/sorbet/rbi/gems/colored.rbi b/sorbet/rbi/gems/colored.rbi
index fe60be2..0c8631d 100644
--- a/sorbet/rbi/gems/colored.rbi
+++ b/sorbet/rbi/gems/colored.rbi
@@ -1,7 +1,7 @@
 # This file is autogenerated. Do not edit it by hand. Regenerate it with:
 #   srb rbi gems

-# typed: strong
+# typed: true
 #
 # If you would like to make changes to this file, great! Please create the gem's shim here:
 #

The problem is that srb init actually has two steps which change the files in the sorbet/rbi/gems folder:

  • the gems subcommand, which creates the RBIs
  • the suggest-typed subcommand, which puts the highest strictness level into each file in a project as it can without introducing errors

So the workaround would be to run

srb rbi gems && srb rbi suggest-typed

but we could also make this the default behavior. I'm marking as a good first issue in case someone wants to implement this.

All 3 comments

I observed the same behavior with my own project 馃憤

Thank you for the very specific bug report! It was incredibly helpful.

In case the repo gets deleted, here's the interesting diff:

diff --git a/sorbet/rbi/gems/colored.rbi b/sorbet/rbi/gems/colored.rbi
index fe60be2..0c8631d 100644
--- a/sorbet/rbi/gems/colored.rbi
+++ b/sorbet/rbi/gems/colored.rbi
@@ -1,7 +1,7 @@
 # This file is autogenerated. Do not edit it by hand. Regenerate it with:
 #   srb rbi gems

-# typed: strong
+# typed: true
 #
 # If you would like to make changes to this file, great! Please create the gem's shim here:
 #

The problem is that srb init actually has two steps which change the files in the sorbet/rbi/gems folder:

  • the gems subcommand, which creates the RBIs
  • the suggest-typed subcommand, which puts the highest strictness level into each file in a project as it can without introducing errors

So the workaround would be to run

srb rbi gems && srb rbi suggest-typed

but we could also make this the default behavior. I'm marking as a good first issue in case someone wants to implement this.

Saw this today too.

Was this page helpful?
0 / 5 - 0 ratings