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

Style/ClassEqualityComparison autocorrect breaks on string #8875

Closed
JeremiahChurch opened this issue Oct 9, 2020 · 0 comments · Fixed by #8876
Closed

Style/ClassEqualityComparison autocorrect breaks on string #8875

JeremiahChurch opened this issue Oct 9, 2020 · 0 comments · Fixed by #8876
Labels

Comments

@JeremiahChurch
Copy link

autocorrect for new Style/ClassEqualityComparison cop incorrectly leaves string

class.name == 'Capybara::RackTest::Driver' becomes instance_of?('Capybara::RackTest::Driver') instead of instance_of?(Capybara::RackTest::Driver)


Expected behavior

run of Style/ClassEqualityComparison should replace class name string with class rather than leaving the class string
instance_of?(Capybara::RackTest::Driver) - without the single quotes is a valid method call

Actual behavior

C: [Corrected] Style/ClassEqualityComparison: Use Object.instance_of? instead of comparing classes.
  page.driver.class.name == 'Capybara::RackTest::Driver'
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

class Example
  page.driver.class.name == 'Capybara::RackTest::Driver'
end

run rubocop -a

becomes

class Example
  page.driver.instance_of?('Capybara::RackTest::Driver')
end

RuboCop version

$ bundle exec rubocop -V
0.93.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)
@koic koic added the bug label Oct 9, 2020
koic added a commit to koic/rubocop that referenced this issue Oct 9, 2020
…Comparison`

Fixes rubocop#8875.

Fix an incorrect auto-correct for `Style/ClassEqualityComparison` when
comparing string class name.
@koic koic closed this as completed in #8876 Oct 9, 2020
koic added a commit that referenced this issue Oct 9, 2020
…s_equality_comparison

[Fix #8875] Fix incorrect autocorrect for `Style/ClassEqualityComparison`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants