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
violates Style/InverseMethods and Style/SymbolProc. Fixing one or the other should be enough but when --auto-correct'd we get
[:a, false, :b, false].select(&:!)
which has the opposite meaning. I realize Style/SymbolProc is not auto-correct-safe but here the correction would be safe except for interfering with Style/InverseMethods (and this can be seen with rubocop --safe --auto-correct).
Expected behavior
After applying the auto-correction for Style/InverseMethods there should be no violation for Style/SymbolProc so it should not apply.
Actual behavior
Style/SymbolProc correction was applied changing the meaning of the code.
Steps to reproduce the problem
have a file test.rb:
puts([:a, false, :b, false].reject { |x| !x })
rubocop --auto-correct test.rb
test.rb:3:6: C: [Corrected] Style/InverseMethods: Use select instead of inverting reject.
puts([:a, false, :b, false].reject { |x| !x })
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:36: C: [Corrected] Style/SymbolProc: Pass &:! as an argument to reject instead of a block.
puts([:a, false, :b, false].reject { |x| !x })
^^^^^^^^^^
ruby test.rb now produces different output
RuboCop version
0.73.0 (using Parser 2.6.3.0, running on ruby 2.6.0 x86_64-darwin18)
The text was updated successfully, but these errors were encountered:
I have made a PR that marks the auto-correct of Style/InverseMethods as incompatible with that of Style/SymbolProc, so in the case they both want to correct, the former should back off.
Drenmi
added a commit
to Drenmi/rubocop
that referenced
this issue
Sep 9, 2019
…ods and Style/SymbolProc
These two cops had an interaction between their auto-corrections which produced
code that wasn't semantically equivalent to the original.
This change fixes that by marking `Style/InverseMethods` auto-correct as
incompatible with that of `Style/SymbolProc`.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
Code like
[:a, false, :b, false].reject { |x| !x }
violates
Style/InverseMethods
andStyle/SymbolProc
. Fixing one or the other should be enough but when--auto-correct
'd we get[:a, false, :b, false].select(&:!)
which has the opposite meaning. I realize Style/SymbolProc is not auto-correct-safe but here the correction would be safe except for interfering with Style/InverseMethods (and this can be seen with
rubocop --safe --auto-correct
).Expected behavior
After applying the auto-correction for Style/InverseMethods there should be no violation for Style/SymbolProc so it should not apply.
Actual behavior
Style/SymbolProc correction was applied changing the meaning of the code.
Steps to reproduce the problem
rubocop --auto-correct test.rb
ruby test.rb
now produces different outputRuboCop version
0.73.0 (using Parser 2.6.3.0, running on ruby 2.6.0 x86_64-darwin18)
The text was updated successfully, but these errors were encountered: