mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 06:44:41 +03:00
59 lines
2.0 KiB
Elm
59 lines
2.0 KiB
Elm
module NoNegationInIfConditionTest exposing (all)
|
|
|
|
import NoNegationInIfCondition exposing (rule)
|
|
import Review.Test
|
|
import Test exposing (Test, describe, test)
|
|
|
|
|
|
all : Test
|
|
all =
|
|
describe "NoNegationInIfCondition"
|
|
[ test "should not report if condition without a not call" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
a = if condition then 1 else 2
|
|
"""
|
|
|> Review.Test.run rule
|
|
|> Review.Test.expectNoErrors
|
|
, test "should report if condition without a not call" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
a = if not condition then 1 else 2
|
|
"""
|
|
|> Review.Test.run rule
|
|
|> Review.Test.expectErrors
|
|
[ Review.Test.error
|
|
{ message = "Don't use if expressions with negated conditions"
|
|
, details = [ "We at fruits.com think that if expressions are more readable when the condition is not negated." ]
|
|
, under = "not"
|
|
}
|
|
|> Review.Test.whenFixed """module A exposing (..)
|
|
a = if condition then 2 else 1
|
|
"""
|
|
]
|
|
, test "should report multi-line if condition without a not call" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
a =
|
|
if not condition then
|
|
1
|
|
else
|
|
2
|
|
"""
|
|
|> Review.Test.run rule
|
|
|> Review.Test.expectErrors
|
|
[ Review.Test.error
|
|
{ message = "Don't use if expressions with negated conditions"
|
|
, details = [ "We at fruits.com think that if expressions are more readable when the condition is not negated." ]
|
|
, under = "not"
|
|
}
|
|
|> Review.Test.whenFixed """module A exposing (..)
|
|
a =
|
|
if condition then
|
|
2
|
|
else
|
|
1
|
|
"""
|
|
]
|
|
]
|