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
Style/ClassEqualityComparison gives incorrect message and autocorrection when comparing class names by calling Module#name
#9582
Comments
…yComparison` Fixes rubocop#9582. This PR fixes incorrect auto-correct for `Style/ClassEqualityComparison` when comparing `Module#name` for equality.
Thanks for creating the issue @caalberts and @koic for the quick PR 🙇 ❤️ I was wondering if it's safe to assume if Please consider this example based on RuboCop warning in GitLab which raises a warning for this bit of code. I think as long as no-one overrides
Note that Should the cop stop warning in those ☝️ cases where |
Well, it's definitely not super safe, but that's a common problem we're facing and in general we aim to optimize for the most common scenario. E.g. in my entire career I've never seen |
Same here but then I checked GitLab's code:
🙈 Anyhow, that's why we have specs and the ability to disable cops in certain cases if needed 😅 Thanks for checking and merging 🙇 |
When calling
Module#name
in a class equality comparison, the error message and autocorrection containsClass.name
, when it should be justClass
Expected behavior
The following test should pass:
Actual behavior
Rubocop message uses
Date.name
instead ofDate
:Autocorrection includes
Date.name
instead ofDate
:Steps to reproduce the problem
Add the test to
spec/rubocop/cop/style/class_equality_comparison_spec.rb
RuboCop version
Seen in 0.93.1, but the test also fails on
master
.The text was updated successfully, but these errors were encountered: