Skip to content

New cop Rails/ClassDescendants that warns developers when they use Class.descendants #1544

@alexanderadam

Description

@alexanderadam

Is your feature request related to a problem? Please describe.

A wise man, let's call him Ben, once said:

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.

And I totally trust him on that because he's making a… GoodJob 🥁

Describe the solution you'd like

A new cop Rails/ClassDescendants that warns developers when they use Class#descendants, explaining the potential issues.

Describe alternatives you've considered

Not being warned by a Cop I guess? 😆

Additional context

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