You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RuboCop auto-correction feature makes invalid correction for class name comparison. For example it replaces obj.class.name == cls_name with obj.instance_of?(cls_name). This is not correct since instance_of() method expects a class as a parameter and not a name of the class. As a result after this replacement code fails with the following error:
Traceback (most recent call last):
1: from test.rb:2:in `<main>'
test.rb:2:in `instance_of?': class or module required (TypeError)
Expected behavior
RuboCop should not perform such replacement, for example obj.class.name == cls_name should stay unmodified.
Actual behavior
RuboCop replaced obj.class.name == cls_name with invalid Ruby code: obj.instance_of?(cls_name)
…lityComparison`
Fixesrubocop#11762.
This PR fixes an incorrect autocorrect for `Style/ClassEqualityComparison`
when comparing a variable or return value for equality.
when a variable or return value of a method is used, it cannot be suggested
and safe autocorrected because the type is not known.
So this PR tweaks the cop that doesn't suggest `instance_of` argument at those times
and doesn't autocorrect. Anyway, detection is possible.
…parison`
Fixes#11762.
This PR fixes an incorrect autocorrect for `Style/ClassEqualityComparison`
when comparing a variable or return value for equality.
when a variable or return value of a method is used, it cannot be suggested
and safe autocorrected because the type is not known.
So this PR tweaks the cop that doesn't suggest `instance_of` argument at those times
and doesn't autocorrect. Anyway, detection is possible.
RuboCop auto-correction feature makes invalid correction for class name comparison. For example it replaces
obj.class.name == cls_name
withobj.instance_of?(cls_name)
. This is not correct sinceinstance_of()
method expects a class as a parameter and not a name of the class. As a result after this replacement code fails with the following error:Expected behavior
RuboCop should not perform such replacement, for example
obj.class.name == cls_name
should stay unmodified.Actual behavior
RuboCop replaced
obj.class.name == cls_name
with invalid Ruby code:obj.instance_of?(cls_name)
Steps to reproduce the problem
Create test.rb file with the following content:
Verify that created file works by running
ruby test.rb
, it should outputSUCCESS
Run RubuCop auto-correction:
rubocop --auto-correct
Now if you run
ruby test.rb
it will fail with error:RuboCop version
The text was updated successfully, but these errors were encountered: