Skip to content

Commit

Permalink
Merge pull request #131 from forresty/presence/square-bracket
Browse files Browse the repository at this point in the history
presence cop: fix [] for ternary expr other hand
  • Loading branch information
koic authored Oct 13, 2019
2 parents 2922567 + 21a3285 commit 048463f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/presence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def replacement(receiver, other)
end

def build_source_for_or_method(other)
if other.parenthesized? || !other.arguments?
if other.parenthesized? || other.method?('[]') || !other.arguments?
" || #{other.source}"
else
method = range_between(
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/rails/presence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
'a(:bar).map(&:baz).presence',
1, 1

it_behaves_like 'offense',
'a.present? ? a : b[:c]',
'a.presence || b[:c]',
1, 1

it_behaves_like 'offense', <<~RUBY.chomp, 'a.presence', 1, 5
if a.present?
a
Expand Down

0 comments on commit 048463f

Please sign in to comment.