mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-27 12:08:51 +03:00
NoUnusedExports: Do not report elements that are not defined
This commit is contained in:
parent
251bca2c12
commit
511db00e29
@ -62,6 +62,7 @@ rule =
|
||||
, get = .scope
|
||||
}
|
||||
|> Rule.withModuleDefinitionVisitor moduleDefinitionVisitor
|
||||
|> Rule.withDeclarationListVisitor declarationListVisitor
|
||||
|> Rule.withExpressionVisitor expressionVisitor
|
||||
, initGlobalContext = initGlobalContext
|
||||
, fromGlobalToModule = fromGlobalToModule
|
||||
@ -194,6 +195,54 @@ elmJsonVisitor maybeProject globalContext =
|
||||
|
||||
|
||||
|
||||
-- DECLARATION LIST VISITOR
|
||||
|
||||
|
||||
declarationListVisitor : List (Node Declaration) -> ModuleContext -> ( List Error, ModuleContext )
|
||||
declarationListVisitor declarations moduleContext =
|
||||
if moduleContext.exposesEverything then
|
||||
( [], moduleContext )
|
||||
|
||||
else
|
||||
let
|
||||
declaredNames : Set String
|
||||
declaredNames =
|
||||
declarations
|
||||
|> List.filterMap (Node.value >> declarationName)
|
||||
|> Set.fromList
|
||||
in
|
||||
( []
|
||||
, { moduleContext | exposed = Dict.filter (\name _ -> Set.member name declaredNames) moduleContext.exposed }
|
||||
)
|
||||
|
||||
|
||||
declarationName : Declaration -> Maybe String
|
||||
declarationName declaration =
|
||||
case declaration of
|
||||
Declaration.FunctionDeclaration function ->
|
||||
function.declaration
|
||||
|> Node.value
|
||||
|> .name
|
||||
|> Node.value
|
||||
|> Just
|
||||
|
||||
Declaration.CustomTypeDeclaration type_ ->
|
||||
Just <| Node.value type_.name
|
||||
|
||||
Declaration.AliasDeclaration alias_ ->
|
||||
Just <| Node.value alias_.name
|
||||
|
||||
Declaration.PortDeclaration port_ ->
|
||||
Just <| Node.value port_.name
|
||||
|
||||
Declaration.InfixDeclaration { operator } ->
|
||||
Just <| Node.value operator
|
||||
|
||||
Declaration.Destructuring _ _ ->
|
||||
Nothing
|
||||
|
||||
|
||||
|
||||
-- GLOBAL EVALUATION
|
||||
|
||||
|
||||
|
@ -176,15 +176,14 @@ main = text ""
|
||||
}
|
||||
|> Review.Test.atExactly { start = { row = 2, column = 23 }, end = { row = 2, column = 27 } }
|
||||
]
|
||||
, Test.skip <|
|
||||
test "should not report a function that does not refer to anything" <|
|
||||
\() ->
|
||||
"""
|
||||
, test "should not report a function that does not refer to anything" <|
|
||||
\() ->
|
||||
"""
|
||||
module A exposing (b)
|
||||
a = 1
|
||||
"""
|
||||
|> Review.Test.runWithProjectData package_ rule
|
||||
|> Review.Test.expectNoErrors
|
||||
|> Review.Test.runWithProjectData package_ rule
|
||||
|> Review.Test.expectNoErrors
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user