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
Given an specific style of comparison expression where the arguments are Modules or Classes Style/InvertibleUnlessCondition's autocorrection can break application logic.
Either this cop should not run when running "safe" autocorrections - via the -a or --autocorrect flags - or, the Cop should ignore expressions comparing Module / Class hierarchies.
Actual behavior
Comparisons using a Module's Class's hierarchy break.
Steps to reproduce the problem
$ ruby --version
ruby 3.1.2p20
Define a method under test which violates this Cop - example_test.rb
Run the rubocop with the Style/InvertibleUnlessCondition Cop in "safe autocorrect" mode:
$ rubocop --autocorrect --only Style/InvertibleUnlessCondition example_test.rb
warning: parser/current is loading parser/ruby31, which recognizes 3.1.4-compliant syntax, but you are running 3.1.2.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Inspecting 1 file
C
Offenses:
example_test.rb:7:5: C: [Corrected] Style/InvertibleUnlessCondition: Favor if with inverted condition over unless.
not_an_error_class = true unless my_mod <= StandardError
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
example_test.rb:15:5: C: [Corrected] Style/InvertibleUnlessCondition: Favor if with inverted condition over unless.
not_an_error_class = true unless my_mod <= StandardError
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 2 offenses detected, 2 offenses corrected
The test will now fail
$ ruby example_test.rb
Run options: --seed 28429
# Running:
F.
Finished in 0.000665s, 3007.5188 runs/s, 3007.5188 assertions/s.
1) Failure:
ExampleTest#test_is_not_ancestor_of_standard_error [example_test.rb:9]:
Expected nil to be truthy.
2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
RuboCop version
Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:
Given an specific style of comparison expression where the arguments are
Module
s orClass
esStyle/InvertibleUnlessCondition
's autocorrection can break application logic.Expected behavior
rubocop --autocorrect --only Style/InvertibleUnlessCondition
Either this cop should not run when running "safe" autocorrections - via the
-a
or--autocorrect
flags - or, the Cop should ignore expressions comparingModule
/Class
hierarchies.Actual behavior
Comparisons using a
Module
'sClass
's hierarchy break.Steps to reproduce the problem
example_test.rb
Style/InvertibleUnlessCondition
Cop in "safe autocorrect" mode:RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler.If you see extension cop versions (e.g.
rubocop-performance
,rubocop-rspec
, and others)output by
rubocop -V
, include them as well. Here's an example:The text was updated successfully, but these errors were encountered: