2019-06-03 01:30:24 +03:00
|
|
|
module NoImportingEverythingTest exposing (all)
|
|
|
|
|
|
|
|
import Elm.Syntax.Range exposing (Location, Range)
|
2019-06-26 14:47:00 +03:00
|
|
|
import Lint.Rule as Rule exposing (Error, Rule)
|
2019-06-03 01:30:24 +03:00
|
|
|
import Lint.Rule.NoImportingEverything exposing (Configuration, rule)
|
2019-06-26 13:32:33 +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-06-27 22:04:41 +03:00
|
|
|
Lint.Test.run (rule options)
|
2019-06-03 01:30:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
error : String -> Error
|
|
|
|
error message =
|
2019-06-26 13:32:33 +03:00
|
|
|
Lint.Test.errorWithoutRange message
|
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
|
|
|
|
import Http
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange []
|
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)
|
|
|
|
import Http exposing (a, b)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange []
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports that expose everything" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange
|
2019-06-03 01:30:24 +03:00
|
|
|
[ error "Do not expose everything from Html" ]
|
|
|
|
, test "should report imports from sub-modules" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html.App exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange [ error "Do not expose everything from Html.App" ]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports from sub-modules (multiple dots)" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html.Foo.Bar exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange [ error "Do not expose everything from Html.Foo.Bar" ]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports that expose everything that are in the exception list" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [ "Html" ] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange []
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports from sub-modules that are in the exception list" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html.App exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange []
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should not report imports from sub-modules (multiple dots)" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html.Foo.Bar exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [ "Html.Foo.Bar" ] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange []
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports whose parent is ignored" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html.Foo.Bar exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [ "Html" ] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange [ error "Do not expose everything from Html.Foo.Bar" ]
|
2019-06-03 01:30:24 +03:00
|
|
|
, test "should report imports whose sub-module is ignored" <|
|
|
|
|
\() ->
|
|
|
|
"""module A exposing (..)
|
|
|
|
import Html exposing (..)
|
|
|
|
"""
|
|
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
2019-06-26 13:32:33 +03:00
|
|
|
|> Lint.Test.expectErrorsWithoutRange [ error "Do not expose everything from Html" ]
|
2019-06-03 01:30:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "NoImportingEverything" tests
|