Skip to content

Commit

Permalink
Fix false positive in ParenthesesInCondition
Browse files Browse the repository at this point in the history
Fixes #461
  • Loading branch information
rrrene committed Nov 4, 2017
1 parent 8a8a9c6 commit 9b338a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/credo/check/readability/parentheses_in_condition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ defmodule Credo.Check.Readability.ParenthesesInCondition do
defp check_for_closing_paren(_start, {:")", _}, [{:and_op, _, _} | _tail], _prev_head) do
false
end
# matches: if( 1 &&& foo ) > bar do
# ^
defp check_for_closing_paren(_start, {:")", _}, [{:rel_op, _, _} | _tail], _prev_head) do
false
end
# matches: if( something ), do:
# ^^
defp check_for_closing_paren(start, {:",", _}, _, {:")", _}) do
Expand Down
10 changes: 10 additions & 0 deletions test/credo/check/readability/parentheses_in_condition_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ defmodule CredoSampleModule do
if (thing && other_thing) || better_thing, do: something
if !better_thing && (thing || other_thing), do: something_else
end
import Bitwise
def bar(foo, bar) do
if (foo &&& 0b1000) > 0, do: bar, else: nil
end
def foobar(foo) do
foo
end
end
""" |> to_source_file
|> refute_issues(@described_check)
Expand Down

0 comments on commit 9b338a8

Please sign in to comment.