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

Also check duplicated mixins in shims and TODO files #1077

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jul 25, 2022

Motivation

While we check scopes and methods duplicated between generated RBIs and shims, we do not check anything about mixins.

Consider this:

# in generated sorbet/rbi/gems/foo@1.0.0.rbi

module Bar; end

class Foo
  include Bar
end
# in manually written shim sorbet/rbi/shims/gems/foo.rbi

class Foo
  include Bar
end

The shim file is actually useless and could be deleted without impacting type checking since the include is already known.

Implementation

We can reuse the indexing mechanism already in place for other properties to check for duplicates. We just need to look for RBI::Mixin nodes and RBI::RequiresAncestor nodes.

One limitation of the static approach is that we do not resolve constants when checking for duplicates so something like this would not be considered a duplicate:

module A
  class B
    include C
  end
end

module A
  class B
    include ::C
  end
end

Because we can't really ensure that C is the same thing as ::C at this level.

Tests

See automated tests.

Using this feature I tried this in core and found one file that can be safely removed.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar added the bugfix label Jul 25, 2022
@Morriar Morriar requested a review from a team as a code owner July 25, 2022 18:53
@Morriar Morriar self-assigned this Jul 25, 2022
@Morriar Morriar merged commit 7d1b853 into main Jul 26, 2022
@Morriar Morriar deleted the at-check-duplicated-mixins branch July 26, 2022 21:02
egiurleo pushed a commit that referenced this pull request Aug 19, 2022
Also check duplicated mixins in shims and TODO files
@paracycle paracycle added the backported Backported to stable branch label Aug 22, 2022
paracycle pushed a commit that referenced this pull request Aug 22, 2022
Also check duplicated mixins in shims and TODO files
@shopify-shipit shopify-shipit bot temporarily deployed to production August 31, 2022 14:40 Inactive
Morriar added a commit to Shopify/rbi-central that referenced this pull request Oct 21, 2022
Those are already generated by Tapioca and are caught by `check-shims`
since Shopify/tapioca#1077 was released.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Backported to stable branch bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants