Skip to content

New Cop: Avoid usage of Class.descendents #110

Closed as not planned
Closed as not planned

Description

@bensheldon

There are two reasons why this is an unreliable solution:

  • it doesn't know about things that have yet to be autoloaded
  • it's non-deterministic with regards to Garbage Collection of classes. If you use Class.descendants in Test, where there is a pattern to dynamically define classes, GC is unpredictable for when those classes are cleaned up and removed by the GC.

cc @jhawthorn

Activity

  1. changed the title [-]Avoid usage of `Class.descendents`[/-] [+]New Cop: Avoid usage of `Class.descendents`[/+] on Oct 13, 2022
  2. alexanderadam commented on Oct 21, 2025

    @alexanderadam
    Contributor

    Is this still relevant with AS's DescendantsTracker and the removal of the Ruby implementation?

  3. bensheldon commented on Oct 21, 2025

    @bensheldon
    ContributorAuthor

    Yes. The reasons for not using 'descendants' are still valid regardless of how descendants is implemented.

    Edit: oh sorry, didn't see this was the GitHub rubocop 🖖🏻

  4. issyl0 commented on Jul 15, 2026

    @issyl0
    Member

    It seems like all attempts to get a cop like this into RuboCop itself have been declined, as have attempts to document the risks have stalled. Closing as it doesn't feel right for a GitHub custom cop that we can never upstream but is a language-specific thing rather than a GitHub-specific thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions