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

presence cop: fix [] for ternary expr other hand #131

Merged
merged 1 commit into from
Oct 13, 2019
Merged

presence cop: fix [] for ternary expr other hand #131

merged 1 commit into from
Oct 13, 2019

Conversation

forresty
Copy link
Contributor

synopsis

when trying autofix code like below:

params[:foo].present? ? params[:foo] : params[:bar]

the existing code will change it to:

params[:foo].presence || params(:bar)

essentially replaces the content of the else or other end of the ternary expression.

investigation and fix

the culprit is this method build_source_for_or_method did not consider the parameter other (which is a SendNode) might be a [] method call.

this tiny patch fixes it.

That being said, I am not confident that this fixes all related problems.

@koic
Copy link
Member

koic commented Sep 25, 2019

Thanks for the patch! That will definitely solve one issue. Could you add the changelog entry to CHANGELOG.md?
https://github.com/rubocop-hq/rubocop-rails/blob/master/CONTRIBUTING.md#changelog-entry-format

@koic koic merged commit 048463f into rubocop:master Oct 13, 2019
@koic
Copy link
Member

koic commented Oct 13, 2019

This PR has been merged and I added the changelog entry for this PR. Thanks!
6244c0e

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

Successfully merging this pull request may close these issues.

2 participants