Shopify / Shopify/tapioca

Action View Class Methods incorrectly mixed into RBIs

Open
#1,096 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

Hello 👋🏼 I'm new to Sorbet and Tapioca and ran into this while adding them to a Rails project at work.

When running bin/tapioca dsl followed by bundle exec srb tc I was presented with a few instances of the following error:

Argument to mixes_in_class_methods must be statically resolvable to a module https://srb.help/5020
    mixes_in_class_methods ::ActionView::Helpers::ClassMethods

Did you mean ActionView::Helpers::SanitizeHelper::ClassMethods? Use `-a` to autocorrect
Full errors collapsed below
sorbet/rbi/dsl/r_spec/rails/helper_example_group.rbi:16: Argument to mixes_in_class_methods must be statically resolvable to a module https://srb.help/5020
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/dsl/r_spec/rails/helper_example_group.rbi:16: Unable to resolve constant ClassMethods https://srb.help/5002
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::UrlHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/r_spec/rails/helper_example_group.rbi:16: Replace with ActionView::Helpers::UrlHelper::ClassMethods
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:10934: ActionView::Helpers::UrlHelper::ClassMethods defined here
       10934 |module ActionView::Helpers::UrlHelper::ClassMethods
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::SanitizeHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/r_spec/rails/helper_example_group.rbi:16: Replace with ActionView::Helpers::SanitizeHelper::ClassMethods
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:8805: ActionView::Helpers::SanitizeHelper::ClassMethods defined here
    8805 |module ActionView::Helpers::SanitizeHelper::ClassMethods
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/dsl/r_spec/rails/view_example_group.rbi:16: Argument to mixes_in_class_methods must be statically resolvable to a module https://srb.help/5020
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/dsl/r_spec/rails/view_example_group.rbi:16: Unable to resolve constant ClassMethods https://srb.help/5002
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::UrlHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/r_spec/rails/view_example_group.rbi:16: Replace with ActionView::Helpers::UrlHelper::ClassMethods
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:10934: ActionView::Helpers::UrlHelper::ClassMethods defined here
       10934 |module ActionView::Helpers::UrlHelper::ClassMethods
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::SanitizeHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/r_spec/rails/view_example_group.rbi:16: Replace with ActionView::Helpers::SanitizeHelper::ClassMethods
    16 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:8805: ActionView::Helpers::SanitizeHelper::ClassMethods defined here
    8805 |module ActionView::Helpers::SanitizeHelper::ClassMethods
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/dsl/action_view/test_case/behavior.rbi:13: Argument to mixes_in_class_methods must be statically resolvable to a module https://srb.help/5020
    13 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

sorbet/rbi/dsl/action_view/test_case/behavior.rbi:13: Unable to resolve constant ClassMethods https://srb.help/5002
    13 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::UrlHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/action_view/test_case/behavior.rbi:13: Replace with ActionView::Helpers::UrlHelper::ClassMethods
    13 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:10934: ActionView::Helpers::UrlHelper::ClassMethods defined here
       10934 |module ActionView::Helpers::UrlHelper::ClassMethods
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Did you mean ActionView::Helpers::SanitizeHelper::ClassMethods? Use `-a` to autocorrect
    sorbet/rbi/dsl/action_view/test_case/behavior.rbi:13: Replace with ActionView::Helpers::SanitizeHelper::ClassMethods
    13 |  mixes_in_class_methods ::ActionView::Helpers::ClassMethods
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sorbet/rbi/gems/actionview@7.0.3.1.rbi:8805: ActionView::Helpers::SanitizeHelper::ClassMethods defined here
    8805 |module ActionView::Helpers::SanitizeHelper::ClassMethods

Running bundle exec srb tc -a as suggested in the message fixes the issue but subsequent runs of bin/tapioca dsl bring them back.

My investigation so far shows that Sorbet's suggestion is spot on. ActionView::Helpers only knows about ClassMethods because it's included by ActionView::Helpers::SanitizeHelper.

ActionView::Helpers.const_source_location(:ClassMethods)
=> ["/usr/local/bundle/gems/rails-html-sanitizer-1.4.3/lib/rails-html-sanitizer.rb", 33]

https://github.com/rails/rails-html-sanitizer/blob/master/lib/rails-html-sanitizer.rb#L33

The RBIs in question are being generated by the ActiveSupportConcern compiler.
The compiler maps over all of the dependencies for a given concern, for example ActionView::TestCase::Behavior in my case, and checks if concern.const_defined?(:ClassMethods), which is how we got to this state.

I was able to work around this issue by creating a shim like so but I'm not sure that's the best solution

# typed: true
module ActionView::Helpers::ClassMethods; end

Any ideas or suggestions to improve this? I'd be happy to open a PR 😄

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/tapioca/dsl/compilers/active_support_concern.rb and the generated sorbet/rbi/dsl/r_spec/rails/helper_example_group.rbi, sorbet/rbi/dsl/r_spec/rails/view_example_group.rbi, and sorbet/rbi/dsl/action_view/test_case/behavior.rbi files. Reproduce with bin/tapioca dsl followed by bundle exec srb tc; done means generation no longer produces invalid ActionView::Helpers::ClassMethods references and type checking succeeds without autocorrection.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.