2019-06-03 01:30:24 +03:00
|
|
|
module NoImportingEverythingTest exposing (all)
|
|
|
|
|
|
|
|
import Lint.Rule.NoImportingEverything exposing (Configuration, rule)
|
2019-07-02 01:04:45 +03:00
|
|
|
import Lint.Test exposing (LintResult)
|
2019-06-26 14:47:00 +03:00
|
|
|
import Test exposing (Test, describe, test)
|
2019-06-03 01:30:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
testRule : Configuration -> String -> LintResult
|
|
|
|
testRule options =
|
2019-07-02 01:04:45 +03:00
|
|
|
Lint.Test.run (rule options)
|
2019-06-03 01:30:24 +03:00
|
|
|
|
|
|
|
|
2019-07-28 01:16:57 +03:00
|
|
|
details : List String
|
|
|
|
details =
|
2019-07-28 15:45:09 +03:00
|
|
|
[ "Exposing `(..)` from a module means making all its exposed functions and types available in the file's namespace. This makes it hard to tell which module a function or type comes from."
|
2019-07-28 01:16:57 +03:00
|
|
|
, "A preferred pattern is to import functions by name (`import Html exposing (div, span)`) or to use qualified imports (`import Html`, then `Html.div`). If the module name is too long, you can give an alias to the imported module (`import Html.Attributes as Attr`)."
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-03 01:30:24 +03:00
|
|
|
tests : List Test
|
|
|
|
tests =
|
|
|
|
[ test "should not report imports that do not expose anything" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html
|
2019-06-30 01:38:32 +03:00
|
|
|
import Http"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectNoErrors
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports that expose functions by name" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html exposing (a)
|
2019-06-30 01:38:32 +03:00
|
|
|
import Http exposing (a, b)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectNoErrors
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports that expose everything" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
2019-06-30 01:38:32 +03:00
|
|
|
import Html exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
2019-06-30 01:38:32 +03:00
|
|
|
{ message = "Do not expose everything from Html"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-06-30 01:38:32 +03:00
|
|
|
, under = ".."
|
|
|
|
}
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.atExactly { start = { row = 2, column = 23 }, end = { row = 2, column = 25 } }
|
2019-06-30 01:38:32 +03:00
|
|
|
]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports from sub-modules" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html.App exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
2019-06-30 01:38:32 +03:00
|
|
|
{ message = "Do not expose everything from Html.App"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-06-30 01:38:32 +03:00
|
|
|
, under = ".."
|
|
|
|
}
|
|
|
|
]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports from sub-modules (multiple dots)" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html.Foo.Bar exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
2019-06-30 01:38:32 +03:00
|
|
|
{ message = "Do not expose everything from Html.Foo.Bar"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-06-30 01:38:32 +03:00
|
|
|
, under = ".."
|
|
|
|
}
|
|
|
|
]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports that expose everything that are in the exception list" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [ "Html" ] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectNoErrors
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports from sub-modules that are in the exception list" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html.App exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectNoErrors
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports from sub-modules (multiple dots)" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html.Foo.Bar exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [ "Html.Foo.Bar" ] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectNoErrors
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports whose parent is ignored" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html.Foo.Bar exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [ "Html" ] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
2019-06-30 01:38:32 +03:00
|
|
|
{ message = "Do not expose everything from Html.Foo.Bar"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-06-30 01:38:32 +03:00
|
|
|
, under = ".."
|
|
|
|
}
|
|
|
|
]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports whose sub-module is ignored" <|
|
|
|
|
\() ->
|
2019-06-30 01:38:32 +03:00
|
|
|
"""module A exposing (a)
|
|
|
|
import Html exposing (..)"""
|
2019-06-03 01:30:24 +03:00
|
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
2019-07-02 01:04:45 +03:00
|
|
|
|> Lint.Test.expectErrors
|
|
|
|
[ Lint.Test.error
|
2019-06-30 01:38:32 +03:00
|
|
|
{ message = "Do not expose everything from Html"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = details
|
2019-06-30 01:38:32 +03:00
|
|
|
, under = ".."
|
|
|
|
}
|
2019-06-27 23:25:45 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-03 01:30:24 +03:00
|
|
|
all : Test
|
|
|
|
all =
|
2019-06-30 01:38:32 +03:00
|
|
|
describe "NoImportingEverything" tests
|