Skip to content

Commit

Permalink
[Fix rubocop#2482] Style/AndOr doesn't crash on !var or ...
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdowad committed Dec 10, 2015
1 parent 45b7aae commit 480bac1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/and_or.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def correct_send(node, corrector)

if node.loc.selector.source == '!'
node = receiver
return unless node.send_type?
_receiver, _method_name, *args = *node
elsif node.loc.selector.source == 'not'
return correct_other(node, corrector)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/and_or_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,13 @@
expect(new_source).to eq('(not arg) && x')
end
end

context 'with !variable on left' do
it "doesn't crash and burn" do
# regression test; see GH issue 2482
inspect_source(cop, '!var or var.empty?')
expect(cop.offenses.size).to eq(1)
end
end
end
end

0 comments on commit 480bac1

Please sign in to comment.