diff --git a/src/Lint/Rule/NoExtraBooleanComparison.elm b/src/Lint/Rule/NoExtraBooleanComparison.elm index 3f930d9a..ef7f3b44 100644 --- a/src/Lint/Rule/NoExtraBooleanComparison.elm +++ b/src/Lint/Rule/NoExtraBooleanComparison.elm @@ -49,8 +49,8 @@ rule = |> Rule.fromSchema -error : String -> Node a -> Error -error comparedValue node = +error : Node a -> String -> Error +error node comparedValue = Rule.error ("Unnecessary comparison with `" ++ comparedValue ++ "`") (Node.range node) @@ -62,6 +62,7 @@ expressionVisitor node = Expression.OperatorApplication operator _ left right -> if isEqualityOperator operator then List.filterMap isTrueOrFalse [ left, right ] + |> List.map (error node) else [] @@ -75,12 +76,12 @@ isEqualityOperator operator = operator == "==" || operator == "/=" -isTrueOrFalse : Node Expression -> Maybe Error +isTrueOrFalse : Node Expression -> Maybe String isTrueOrFalse node = case Node.value node of FunctionOrValue [] functionOrValue -> if functionOrValue == "True" || functionOrValue == "False" then - Just <| error functionOrValue node + Just functionOrValue else Nothing diff --git a/tests/NoExtraBooleanComparisonTest.elm b/tests/NoExtraBooleanComparisonTest.elm index 943247a1..3cc67cf9 100644 --- a/tests/NoExtraBooleanComparisonTest.elm +++ b/tests/NoExtraBooleanComparisonTest.elm @@ -37,7 +37,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `True`" - , under = " True " + , under = "b == True" } ] , test "should report condition with `True == expr`" <| @@ -46,7 +46,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `True`" - , under = " True " + , under = "True == b" } ] , test "should report condition with `expr == False`" <| @@ -55,7 +55,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `False`" - , under = " False " + , under = "b == False" } ] , test "should report condition with `False == expr`" <| @@ -64,7 +64,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `False`" - , under = " False " + , under = "False == b" } ] , test "should report condition with `expr /= True`" <| @@ -73,7 +73,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `True`" - , under = " True " + , under = "b /= True" } ] , test "should report condition with `True /= expr`" <| @@ -82,7 +82,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `True`" - , under = " True " + , under = "True /= b" } ] , test "should report condition with `expr /= False`" <| @@ -91,7 +91,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `False`" - , under = " False " + , under = "b /= False" } ] , test "should report condition with `False /= expr`" <| @@ -100,7 +100,7 @@ d = if n >= 1 then 1 else 2 |> Lint.Test2.expectErrors [ Lint.Test2.error { message = "Unnecessary comparison with `False`" - , under = " False " + , under = "False /= b" } ] ]