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

Auto correction of 'Avoid using nested modifiers' changes logic incorrectly #2696

Closed
marcocanderle opened this issue Jan 21, 2016 · 0 comments

Comments

@marcocanderle
Copy link

Hello,

I think I found an issue with the autocorrection for a Rails file.

I applied rubocop autocorrection
bundle exec rubocop --rails -a

to a file that contains this line:

 changes.each { |k, v| amended_data[k] = v if !amended_data[k] && k != 'amended_data' } unless changes['report_status'] if self.amended? || self.reported?

And the autocorrection resulted in this line change:

 changes.each { |k, v| amended_data[k] = v if !amended_data[k] && k != 'amended_data' } if self.amended? || self.reported? && !changes['report_status']

However, this changes the logic if compared to the unless/if modifiers used on the original code because of missing parenthesis on the || clause.

The correct code output from the automatic correction should have been:

changes.each { |k, v| amended_data[k] = v if !amended_data[k] && k != 'amended_data' } if (self.amended? || self.reported?) && !changes['report_status']

Thanks!

bbatsov added a commit that referenced this issue Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant