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/InverseMethods autofix leaves a parenthesis #7682

Closed
mbalc opened this issue Jan 31, 2020 · 0 comments · Fixed by #7732
Closed

Style/InverseMethods autofix leaves a parenthesis #7682

mbalc opened this issue Jan 31, 2020 · 0 comments · Fixed by #7732
Labels

Comments

@mbalc
Copy link

mbalc commented Jan 31, 2020

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'
@koic koic added the bug label Feb 1, 2020
tejasbubane added a commit to tejasbubane/rubocop that referenced this issue Feb 22, 2020
koic added a commit that referenced this issue Feb 22, 2020
[Fix #7682] Fix `Style/InverseMethods` autofix leaving parenthesis
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