Improve the range for NoExtraBooleanComparison

This commit is contained in:
Jeroen Engels 2019-06-30 11:56:28 +02:00
parent e96b6610b2
commit 40cd398e35
2 changed files with 13 additions and 12 deletions

View File

@ -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

View File

@ -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"
}
]
]