Report unused import aliases

This commit is contained in:
Jeroen Engels 2019-07-25 09:14:33 +02:00
parent 78562d1de5
commit 527ee1c43a
2 changed files with 28 additions and 1 deletions

View File

@ -220,10 +220,24 @@ importVisitor node context =
)
Just declaredImports ->
let
contextWithoutImports : Context
contextWithoutImports =
case Node.value node |> .moduleAlias of
Just moduleAlias ->
register
ModuleAlias
(Node.range moduleAlias)
(Node.value moduleAlias |> getModuleName)
context
Nothing ->
context
in
( []
, List.foldl
(\( variableType, range, name ) context_ -> register variableType range name context_)
context
contextWithoutImports
(collectFromExposing declaredImports)
)

View File

@ -344,6 +344,19 @@ import Html.Styled.Attributes as Html"""
}
|> Lint.Test.atExactly { start = { row = 2, column = 34 }, end = { row = 2, column = 38 } }
]
, test "should report unused import alias even if it exposes a used type" <|
\() ->
testRule """module A exposing (a)
import Html.Styled.Attributes as Html exposing (Attribute)
a : Attribute
a = ()"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Module alias `Html` is not used"
, under = "Html"
}
|> Lint.Test.atExactly { start = { row = 2, column = 34 }, end = { row = 2, column = 38 } }
]
, test "should not report import that exposes a used exposed type" <|
\() ->
testRule """module A exposing (a)