2019-07-05 00:57:55 +03:00
|
|
|
module NoUnusedTypeConstructorsTest exposing (all)
|
|
|
|
|
|
|
|
import Lint.Rule.NoUnusedTypeConstructors exposing (rule)
|
|
|
|
import Lint.Test exposing (LintResult)
|
|
|
|
import Test exposing (Test, describe, test)
|
|
|
|
|
|
|
|
|
|
|
|
testRule : String -> LintResult
|
|
|
|
testRule =
|
|
|
|
Lint.Test.run rule
|
|
|
|
|
|
|
|
|
2019-07-28 01:16:57 +03:00
|
|
|
details : List String
|
|
|
|
details =
|
|
|
|
[ "Since it is not being used, I recommend removing it. It should make the code clearer to read for other people."
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-05 00:57:55 +03:00
|
|
|
tests : List Test
|
|
|
|
tests =
|
|
|
|
[ test "should not report non-exposed variables" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (b)
|
|
|
|
a = 1"""
|
|
|
|
|> Lint.Test.expectNoErrors
|
|
|
|
, test "should not report used type constructors" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (b)
|
|
|
|
type Foo = Bar | Baz
|
|
|
|
a = Bar
|
|
|
|
b = Baz"""
|
|
|
|
|> Lint.Test.expectNoErrors
|
|
|
|
, test "should not report unused type constructors when module is exposing all" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (..)
|
|
|
|
type Foo = Bar | Baz
|
|
|
|
"""
|
|
|
|
|> Lint.Test.expectNoErrors
|
|
|
|
, test "should not report unused type constructors when module is exposing the constructors of that type" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (Foo(..))
|
|
|
|
type Foo = Bar | Baz
|
|
|
|
"""
|
|
|
|
|> Lint.Test.expectNoErrors
|
|
|
|
, test "should report unused type constructors" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (b)
|
|
|
|
type Foo = Bar | Baz"""
|
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
|
|
|
{ message = "Type constructor `Bar` is not used."
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-07-05 00:57:55 +03:00
|
|
|
, under = "Bar"
|
|
|
|
}
|
|
|
|
, Lint.Test.error
|
|
|
|
{ message = "Type constructor `Baz` is not used."
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-07-05 00:57:55 +03:00
|
|
|
, under = "Baz"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
, test "should report unused type constructors, even if the type is exposed" <|
|
|
|
|
\() ->
|
|
|
|
testRule """module A exposing (Foo)
|
|
|
|
type Foo = Bar | Baz"""
|
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
|
|
|
{ message = "Type constructor `Bar` is not used."
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-07-05 00:57:55 +03:00
|
|
|
, under = "Bar"
|
|
|
|
}
|
|
|
|
, Lint.Test.error
|
|
|
|
{ message = "Type constructor `Baz` is not used."
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-07-05 00:57:55 +03:00
|
|
|
, under = "Baz"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "NoUnusedTypeConstructors" tests
|