2019-06-03 01:30:24 +03:00
|
|
|
module NoImportingEverythingTest exposing (all)
|
|
|
|
|
2020-04-08 01:14:03 +03:00
|
|
|
import NoImportingEverything exposing (rule)
|
|
|
|
import Review.Test
|
2020-04-08 19:36:56 +03:00
|
|
|
import Test exposing (Test, describe, test)
|
2019-06-27 23:25:45 +03:00
|
|
|
|
|
|
|
|
2019-06-03 01:30:24 +03:00
|
|
|
all : Test
|
|
|
|
all =
|
2020-04-08 01:14:03 +03:00
|
|
|
describe "NoImportingEverything"
|
|
|
|
[ test "should not report imports without exposing clause" <|
|
|
|
|
\_ ->
|
|
|
|
"""module A exposing (thing)
|
|
|
|
import Html
|
|
|
|
import Html as B
|
|
|
|
"""
|
|
|
|
|> Review.Test.run (rule [])
|
|
|
|
|> Review.Test.expectNoErrors
|
|
|
|
, test "should not report imports that expose some elements" <|
|
|
|
|
\_ ->
|
|
|
|
"""module A exposing (thing)
|
|
|
|
import Html exposing (B, c)
|
|
|
|
"""
|
|
|
|
|> Review.Test.run (rule [])
|
|
|
|
|> Review.Test.expectNoErrors
|
|
|
|
, test "should not report imports that expose all constructors of a type" <|
|
|
|
|
\_ ->
|
|
|
|
"""module A exposing (thing)
|
|
|
|
import Html exposing (B(..))
|
|
|
|
"""
|
|
|
|
|> Review.Test.run (rule [])
|
|
|
|
|> Review.Test.expectNoErrors
|
|
|
|
, test "should report imports that expose everything" <|
|
|
|
|
\_ ->
|
|
|
|
"""module A exposing (thing)
|
|
|
|
import Html exposing (..)
|
|
|
|
"""
|
|
|
|
|> Review.Test.run (rule [])
|
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
|
|
|
{ message = "Prefer listing what you wish to import and/or using qualified imports"
|
2020-08-09 19:55:15 +03:00
|
|
|
, details = [ "When you import everything from a module it becomes harder to know where a function or a type comes from." ]
|
2020-04-08 01:14:03 +03:00
|
|
|
, under = "(..)"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
, test "should not report imports that are in the exceptions list" <|
|
|
|
|
\_ ->
|
|
|
|
"""module A exposing (thing)
|
|
|
|
import Html exposing (..)
|
|
|
|
import Thing.Foo as Foo exposing (..)
|
|
|
|
"""
|
|
|
|
|> Review.Test.run (rule [ "Html", "Thing.Foo" ])
|
|
|
|
|> Review.Test.expectNoErrors
|
|
|
|
]
|