Closed
Description
Autocorrecting an issue highlighted by Style/InverseMethods cop causes my code to be corrected into something that is not possible to be run.
This is an example file that I've been using to verify the issue - an adapted excerpt from code modifying Spree framework:
test.rb
:
Spree::Shipment.class_eval do
state_machine initial: :pending, use_transactions: false do
event :x do
transition from: :y, to: :z, if: lambda { |shipment|
# Fix for #2040
!(shipment.inventory_units.any? &:backordered?)
}
end
end
end
The issue getting highlighted and corrected here is in the line 6th - cop wants to use none?
instead of any?
.
Expected behavior
Line 6 should be corrected to
shipment.inventory_units.none? &:backordered?
or
(shipment.inventory_units.none? &:backordered?)
Actual behavior
Line 6 got corrected to
shipment.inventory_units.none? &:backordered?)
leaving a closing parenthesis (while the opening one got removed) at the end of the line and breaking the code.
Steps to reproduce the problem
- Autofix the above test file with Rubocop config included at the bottom of the issue - I used
rubocop --auto-correct app/models/spree/test.rb
RuboCop version
✔ bundle exec rubocop -V 1.33 Dur 16:22 98% █
0.79.0 (using Parser 2.7.0.2, running on ruby 2.5.1 x86_64-linux)
I also used rubocop-rails
version 2.4.2
My rubocop config:
.rubocop.yml
:
require: rubocop-rails
Layout/EmptyLinesAroundBlockBody:
EnforcedStyle: no_empty_lines
Layout/EmptyLinesAroundClassBody:
EnforcedStyle: no_empty_lines
Layout/EmptyLinesAroundMethodBody:
Enabled: true
Layout/EmptyLinesAroundModuleBody:
EnforcedStyle: no_empty_lines
Layout/TrailingEmptyLines:
EnforcedStyle: final_newline
Layout/LineLength:
Max: 120
Layout/MultilineMethodCallIndentation:
Enabled: true
Metrics/AbcSize:
Max: 20 # default: 15
Metrics/ClassLength:
Max: 400 # default: 100
Security/Eval:
Enabled: true
Security/JSONLoad:
Enabled: true
Security/MarshalLoad:
Enabled: true
Security/YAMLLoad:
Enabled: true
Style/Alias:
EnforcedStyle: prefer_alias
Style/ClassAndModuleChildren:
Enabled: false # module A ; module B ; module C < A::B and
# module A ; module B ; module C < B are impossible (module can't be superclass)
# module A ; module B::C < B is blocked by this inspection
Style/CommentedKeyword:
Enabled: false
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: 'comma'
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: 'comma'
Activity
Style/InverseMethods
autofix leaving parenthesis #7732Merge pull request #7732 from tejasbubane/fix-7682