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

Initialize sorbet #8012

Merged
merged 3 commits into from
Sep 12, 2023
Merged

Initialize sorbet #8012

merged 3 commits into from
Sep 12, 2023

Conversation

JamieMagee
Copy link
Contributor

This is step 2 in the adopting sorbet in an existing codebase guide.

Here's the full output:

bundle exec tapioca init
bundle exec tapioca init
      create  sorbet/config
      create  sorbet/tapioca/config.yml
      create  sorbet/tapioca/require.rb
      create  bin/tapioca
Retrieving index from central repository... Done
Listing gems from Gemfile.lock... Done
Removing annotations for gems that have been removed...  Nothing to do
Fetching gem annotations from central repository...

  Fetched faraday
      create  sorbet/rbi/annotations/faraday.rbi

  Fetched rainbow
      create  sorbet/rbi/annotations/rainbow.rbi

  Fetched webmock
      create  sorbet/rbi/annotations/webmock.rbi

Done
Removing RBI files of gems that have been removed:

  Nothing to do.

Generating RBI files of gems that are added or updated:

Requiring all gems to prepare for compiling... W, [2023-09-11T22:38:10.650790 #3051466]  WARN -- rbs: RBS::Parser::SyntaxError is deprecated and will be deleted in RBS 2.0.
W, [2023-09-11T22:38:10.651109 #3051466]  WARN -- rbs: RBS::Parser::SemanticsError is deprecated and will be deleted in RBS 2.0.
W, [2023-09-11T22:38:10.651401 #3051466]  WARN -- rbs: RBS::Parser::LexerError is deprecated and will be deleted in RBS 2.0.
W, [2023-09-11T22:38:10.651716 #3051466]  WARN -- rbs: RBS::Parser::LocatedValue is deprecated and will be deleted in RBS 2.0.
 Done

  Compiled ast
      create  sorbet/rbi/gems/ast@2.4.2.rbi

  Compiled aws-eventstream
      create  sorbet/rbi/gems/aws-eventstream@1.2.0.rbi

  Compiled aws-partitions
      create  sorbet/rbi/gems/aws-partitions@1.820.0.rbi

  Compiled addressable
      create  sorbet/rbi/gems/addressable@2.8.5.rbi

  Compiled aws-sigv4
      create  sorbet/rbi/gems/aws-sigv4@1.6.0.rbi

  Compiled backport
      create  sorbet/rbi/gems/backport@1.2.0.rbi

  Compiled base64
      create  sorbet/rbi/gems/base64@0.1.1.rbi

  Compiled benchmark
      create  sorbet/rbi/gems/benchmark@0.2.1.rbi

  Compiled citrus
      create  sorbet/rbi/gems/citrus@3.0.2.rbi

  Compiled commonmarker
      create  sorbet/rbi/gems/commonmarker@0.23.10.rbi

  Compiled crack
      create  sorbet/rbi/gems/crack@0.4.5.rbi

  Compiled diff-lcs
      create  sorbet/rbi/gems/diff-lcs@1.5.0.rbi

  Compiled docker_registry2
      create  sorbet/rbi/gems/docker_registry2@1.18.0.rbi

  Compiled aws-sdk-ecr
      create  sorbet/rbi/gems/aws-sdk-ecr@1.64.0.rbi

  Compiled e2mmap (empty output)
      create  sorbet/rbi/gems/e2mmap@0.1.0.rbi

  Compiled erubi
      create  sorbet/rbi/gems/erubi@1.12.0.rbi

  Compiled domain_name
      create  sorbet/rbi/gems/domain_name@0.5.20190701.rbi

  Compiled aws-sdk-codecommit (empty output)
      create  sorbet/rbi/gems/aws-sdk-codecommit@1.59.0.rbi

  Compiled excon
      create  sorbet/rbi/gems/excon@0.102.0.rbi

  Compiled faraday-net_http
      create  sorbet/rbi/gems/faraday-net_http@3.0.2.rbi

  Compiled faraday-retry
      create  sorbet/rbi/gems/faraday-retry@2.2.0.rbi

  Compiled faraday
      create  sorbet/rbi/gems/faraday@2.7.10.rbi

  Compiled hashdiff
      create  sorbet/rbi/gems/hashdiff@1.0.1.rbi

  Compiled http-accept
      create  sorbet/rbi/gems/http-accept@1.7.0.rbi

  Compiled gpgme
      create  sorbet/rbi/gems/gpgme@2.0.22.rbi

  Compiled http-cookie
      create  sorbet/rbi/gems/http-cookie@1.0.5.rbi

  Compiled io-console (empty output)
      create  sorbet/rbi/gems/io-console@0.6.0.rbi

  Compiled gitlab
  Compiled aws-sdk-core
      create  sorbet/rbi/gems/gitlab@4.19.0.rbi

  Compiled httparty
      create  sorbet/rbi/gems/httparty@0.21.0.rbi

      create  sorbet/rbi/gems/aws-sdk-core@3.181.0.rbi

  Compiled jaro_winkler
      create  sorbet/rbi/gems/jaro_winkler@1.5.6.rbi

  Compiled irb
      create  sorbet/rbi/gems/irb@1.8.1.rbi

  Compiled json
      create  sorbet/rbi/gems/json@2.6.3.rbi

  Compiled kramdown-parser-gfm
      create  sorbet/rbi/gems/kramdown-parser-gfm@1.1.0.rbi

  Compiled jmespath
      create  sorbet/rbi/gems/jmespath@1.6.2.rbi

  Compiled mime-types
      create  sorbet/rbi/gems/mime-types@3.5.1.rbi

  Compiled mime-types-data
      create  sorbet/rbi/gems/mime-types-data@3.2023.0808.rbi

  Compiled mini_mime
      create  sorbet/rbi/gems/mini_mime@1.1.5.rbi

  Compiled kwalify
      create  sorbet/rbi/gems/kwalify@0.7.2.rbi

  Compiled kramdown
  Compiled mini_portile2 (empty output)
      create  sorbet/rbi/gems/mini_portile2@2.8.4.rbi

      create  sorbet/rbi/gems/kramdown@2.4.0.rbi

  Compiled multi_xml
      create  sorbet/rbi/gems/multi_xml@0.6.0.rbi

  Compiled netrc
      create  sorbet/rbi/gems/netrc@0.11.0.rbi

  Compiled parallel
      create  sorbet/rbi/gems/parallel@1.23.0.rbi

  Compiled parallel_tests
      create  sorbet/rbi/gems/parallel_tests@4.2.1.rbi

  Compiled parseconfig
      create  sorbet/rbi/gems/parseconfig@1.0.8.rbi

  Compiled nokogiri
      create  sorbet/rbi/gems/nokogiri@1.15.4.rbi

  Compiled prettier_print
      create  sorbet/rbi/gems/prettier_print@1.2.1.rbi

  Compiled octokit
      create  sorbet/rbi/gems/octokit@6.1.1.rbi

  Compiled psych
      create  sorbet/rbi/gems/psych@5.1.0.rbi

  Compiled public_suffix
      create  sorbet/rbi/gems/public_suffix@5.0.3.rbi

  Compiled rainbow
      create  sorbet/rbi/gems/rainbow@3.1.1.rbi

  Compiled racc
      create  sorbet/rbi/gems/racc@1.7.1.rbi

  Compiled language_server-protocol
      create  sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi

  Compiled rake
      create  sorbet/rbi/gems/rake@13.0.6.rbi

  Compiled rbi
      create  sorbet/rbi/gems/rbi@0.0.17.rbi

  Compiled reek
      create  sorbet/rbi/gems/reek@6.1.4.rbi

  Compiled rbs
      create  sorbet/rbi/gems/rbs@2.8.4.rbi

  Compiled reline (empty output)
      create  sorbet/rbi/gems/reline@0.3.8.rbi

  Compiled regexp_parser
      create  sorbet/rbi/gems/regexp_parser@2.8.1.rbi

  Compiled reverse_markdown
      create  sorbet/rbi/gems/reverse_markdown@2.1.1.rbi

  Compiled rest-client
      create  sorbet/rbi/gems/rest-client@2.1.0.rbi

  Compiled rspec
      create  sorbet/rbi/gems/rspec@3.12.0.rbi

  Compiled rexml
      create  sorbet/rbi/gems/rexml@3.2.6.rbi

  Compiled rspec-core
      create  sorbet/rbi/gems/rspec-core@3.12.2.rbi

  Compiled rspec-its
      create  sorbet/rbi/gems/rspec-its@1.3.0.rbi

  Compiled rspec-expectations
      create  sorbet/rbi/gems/rspec-expectations@3.12.3.rbi

  Compiled rspec-support
      create  sorbet/rbi/gems/rspec-support@3.12.1.rbi

  Compiled rspec-mocks
      create  sorbet/rbi/gems/rspec-mocks@3.12.6.rbi

  Compiled rdoc
      create  sorbet/rbi/gems/rdoc@6.5.0.rbi

  Compiled rubocop-ast
  Compiled rubocop-performance
      create  sorbet/rbi/gems/rubocop-ast@1.29.0.rbi

      create  sorbet/rbi/gems/rubocop-performance@1.19.0.rbi

  Compiled ruby2_keywords (empty output)
      create  sorbet/rbi/gems/ruby2_keywords@0.0.5.rbi

  Compiled sawyer
      create  sorbet/rbi/gems/sawyer@0.9.2.rbi

  Compiled ruby-progressbar
      create  sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi

  Compiled spoom
      create  sorbet/rbi/gems/spoom@1.2.3.rbi

  Compiled stackprof
      create  sorbet/rbi/gems/stackprof@0.2.25.rbi

  Compiled stringio (empty output)
      create  sorbet/rbi/gems/stringio@3.0.8.rbi

  Compiled solargraph
      create  sorbet/rbi/gems/solargraph@0.49.0.rbi

  Compiled tapioca
      create  sorbet/rbi/gems/tapioca@0.11.8.rbi

  Compiled terminal-table (empty output)
      create  sorbet/rbi/gems/terminal-table@3.0.2.rbi

  Compiled thor
      create  sorbet/rbi/gems/thor@1.2.2.rbi

  Compiled tilt
      create  sorbet/rbi/gems/tilt@2.2.0.rbi

  Compiled toml-rb
      create  sorbet/rbi/gems/toml-rb@2.2.0.rbi

  Compiled unf
      create  sorbet/rbi/gems/unf@0.1.4.rbi

  Compiled unf_ext (empty output)
      create  sorbet/rbi/gems/unf_ext@0.0.8.2.rbi

  Compiled unicode-display_width
      create  sorbet/rbi/gems/unicode-display_width@2.4.2.rbi

  Compiled unparser
      create  sorbet/rbi/gems/unparser@0.6.8.rbi

  Compiled syntax_tree
      create  sorbet/rbi/gems/syntax_tree@6.1.1.rbi

  Compiled vcr
      create  sorbet/rbi/gems/vcr@6.2.0.rbi

  Compiled webmock
      create  sorbet/rbi/gems/webmock@3.19.1.rbi

  Compiled webrick
      create  sorbet/rbi/gems/webrick@1.8.1.rbi

  Compiled yard-sorbet
      create  sorbet/rbi/gems/yard-sorbet@0.8.1.rbi

  Compiled rubocop
      create  sorbet/rbi/gems/rubocop@1.56.3.rbi

  Compiled yard
      create  sorbet/rbi/gems/yard@0.9.34.rbi

  Compiled parser
      create  sorbet/rbi/gems/parser@3.2.2.3.rbi


Checking generated RBI files...  Done

  Changed strictness of sorbet/rbi/gems/rdoc@6.5.0.rbi to `typed: false` (conflicting with DSL files)

  Changed strictness of sorbet/rbi/gems/tapioca@0.11.8.rbi to `typed: false` (conflicting with DSL files)

All operations performed in working directory.
Please review changes and commit them.

Finding all unresolved constants, this may take a few seconds... Done

All unresolved constants have been written to sorbet/rbi/todo.rbi.
Please review changes and commit them.
This project is now set up for use with Sorbet and Tapioca

The sorbet/ folder should exist and look something like this:

├── config             # Default options to be passed to Sorbet on every run
└── rbi/
  ├── annotations/     # Type definitions pulled from the rbi-central repository
  ├── gems/            # Autogenerated type definitions for your gems
  └── todo.rbi         # Constants which were still missing after RBI generation
└── tapioca/
  ├── config.yml       # Default options to be passed to Tapioca
  └── require.rb       # A file where you can make requires from gems that might be needed for gem RBI generation

Please check this folder into version control.

🤔 What's next

1. Many Ruby applications use metaprogramming DSLs to dynamically generate constants and methods.
  To generate type definitions for any DSLs in your application, run:

  bin/tapioca dsl

2. Check whether the constants in the sorbet/rbi/todo.rbi file actually exist in your project.
  It is possible that some of these constants are typos, and leaving them in todo.rbi will
  hide errors in your application. Ideally, you should be able to remove all definitions
  from this file and delete it.

3. Typecheck your project:

  bundle exec srb tc

  There should not be any typechecking errors.

4. Upgrade a file marked "# typed: false" to "# typed: true".
  Then, run: bundle exec srb tc and try to fix any errors.

  You can use Spoom to bump files for you:

  spoom bump --from false --to true

  To learn more about Spoom, visit: https://github.com/Shopify/spoom

5. Add signatures to your methods with sig. To learn how, read: https://sorbet.org/docs/sigs

Documentation
We recommend skimming these docs to get a feel for how to use Sorbet:
- Gradual Type Checking: https://sorbet.org/docs/gradual
- Enabling Static Checks: https://sorbet.org/docs/static
- RBI Files: https://sorbet.org/docs/rbi

Followed by the initial type check using sorbet:

bundle exec srb tc
bundler/spec/dependabot/bundler/file_updater_spec.rb:451: Unable to resolve constant RUBY_VERSIONS https://srb.help/5002
     451 |            described_class::RubyRequirementSetter::RUBY_VERSIONS + ["99.0.0"]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean Dependabot::Bundler::FileUpdater::RubyRequirementSetter::RUBY_VERSIONS? Use -a to autocorrect
    bundler/spec/dependabot/bundler/file_updater_spec.rb:451: Replace with Dependabot::Bundler::FileUpdater::RubyRequirementSetter::RUBY_VERSIONS
     451 |            described_class::RubyRequirementSetter::RUBY_VERSIONS + ["99.0.0"]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    bundler/lib/dependabot/bundler/file_updater/ruby_requirement_setter.rb:13: Dependabot::Bundler::FileUpdater::RubyRequirementSetter::RUBY_VERSIONS defined here
    13 |        RUBY_VERSIONS = %w(
                ^^^^^^^^^^^^^
  Did you mean RUBY_VERSIONS? Use -a to autocorrect
    bundler/spec/dependabot/bundler/file_updater_spec.rb:451: Replace with RUBY_VERSIONS
     451 |            described_class::RubyRequirementSetter::RUBY_VERSIONS + ["99.0.0"]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/todo.rbi:23: RUBY_VERSIONS defined here
    23 |module T.untyped::RUBY_VERSIONS; end
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

common/spec/dependabot/dependency_file_spec.rb:317: Unable to resolve constant BASE64 https://srb.help/5002
     317 |          content_encoding: described_class::ContentEncoding::BASE64,
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean Dependabot::Clients::GitlabWithRetries::ContentEncoding::BASE64? Use -a to autocorrect
    common/spec/dependabot/dependency_file_spec.rb:317: Replace with Dependabot::Clients::GitlabWithRetries::ContentEncoding::BASE64
     317 |          content_encoding: described_class::ContentEncoding::BASE64,
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    common/lib/dependabot/clients/gitlab_with_retries.rb:11: Dependabot::Clients::GitlabWithRetries::ContentEncoding::BASE64 defined here
    11 |        BASE64 = "base64"
                ^^^^^^
  Did you mean Dependabot::DependencyFile::ContentEncoding::BASE64? Use -a to autocorrect
    common/spec/dependabot/dependency_file_spec.rb:317: Replace with Dependabot::DependencyFile::ContentEncoding::BASE64
     317 |          content_encoding: described_class::ContentEncoding::BASE64,
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    common/lib/dependabot/dependency_file.rb:13: Dependabot::DependencyFile::ContentEncoding::BASE64 defined here
    13 |      BASE64 = "base64"
              ^^^^^^
  Did you mean BASE64? Use -a to autocorrect
    common/spec/dependabot/dependency_file_spec.rb:317: Replace with BASE64
     317 |          content_encoding: described_class::ContentEncoding::BASE64,
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/todo.rbi:22: BASE64 defined here
    22 |module T.untyped::BASE64; end
        ^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/todo.rbi:22: Dynamic constant references are unsupported https://srb.help/4014
    22 |module T.untyped::BASE64; end
               ^^^^^^^^^

sorbet/rbi/todo.rbi:23: Dynamic constant references are unsupported https://srb.help/4014
    23 |module T.untyped::RUBY_VERSIONS; end
               ^^^^^^^^^

updater/lib/dependabot/sentry.rb:6: The super class Raven::Processor of ExceptionSanitizer does not derive from Class https://srb.help/5067
     6 |class ExceptionSanitizer < Raven::Processor
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/todo.rbi:9: Raven::Processor defined here
     9 |module ::Raven::Processor; end
        ^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 5

This led me to make 3 changes on top of the default initialization:

  • Two issues of error 5002

    Sorbet doesn't seem to be able to resolve constants on RSpec described_class, at least out of the box. For now I've hardcoded the specific constants, and will come back to it later.

  • An unresolved reference to sentry-raven

    The top level Gemfile doesn't import updater, so sentry-raven isn't installed and tapioca init doesn't generate types for it. For now, I've added updater to the list of ignored directories, and will circle back to it at a later date.

After making the above changes sorbet runs with no errors:

$ srb tc
No errors! Great job.

@JamieMagee JamieMagee requested a review from a team as a code owner September 11, 2023 23:15
@JamieMagee JamieMagee mentioned this pull request Sep 11, 2023
8 tasks
@github-actions github-actions bot added the L: ruby:bundler RubyGems via bundler label Sep 11, 2023
@jakecoffman jakecoffman enabled auto-merge (squash) September 12, 2023 17:19
@jakecoffman jakecoffman merged commit b69bcb3 into dependabot:main Sep 12, 2023
@JamieMagee JamieMagee deleted the jamiemagee/sorbet-init branch September 12, 2023 17:42
@JamieMagee JamieMagee added the sorbet 🍦 Relates to Sorbet types label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: ruby:bundler RubyGems via bundler sorbet 🍦 Relates to Sorbet types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants