From 9b338a886bae547925ad19e444b09a5f682bb508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Sat, 4 Nov 2017 19:35:04 +0100 Subject: [PATCH] Fix false positive in ParenthesesInCondition Fixes #461 --- .../check/readability/parentheses_in_condition.ex | 5 +++++ .../readability/parentheses_in_condition_test.exs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/credo/check/readability/parentheses_in_condition.ex b/lib/credo/check/readability/parentheses_in_condition.ex index da16468a0..5c35ce6ff 100644 --- a/lib/credo/check/readability/parentheses_in_condition.ex +++ b/lib/credo/check/readability/parentheses_in_condition.ex @@ -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 diff --git a/test/credo/check/readability/parentheses_in_condition_test.exs b/test/credo/check/readability/parentheses_in_condition_test.exs index 47a4b7117..b5d263dae 100644 --- a/test/credo/check/readability/parentheses_in_condition_test.exs +++ b/test/credo/check/readability/parentheses_in_condition_test.exs @@ -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)