Skip to content

Style/ClassEqualityComparison autocorrect is not safe #12097

@yenshirak

Description

@yenshirak

It is not safe to autocorrect foo.class.name == 'Bar' to foo.instance_of?(::Bar) because ::Bar may not be defined.


Expected behavior

The Style/ClassEqualityComparison cop autocorrect shouldn't be marked as safe because the autocorrected code may cause NameError.

Actual behavior

foo.class.name == 'Bar' is autocorrected to foo.instance_of?(::Bar).

Steps to reproduce the problem

Create a file with foo.class.name == 'Bar' and run rubocop -a.

RuboCop version

1.55.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions