mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-26 19:24:40 +03:00
Make NoUnusedVariables handle port module declarations
This commit is contained in:
parent
6ee43b9d84
commit
60b7ee4710
@ -189,6 +189,16 @@ getExported exportType =
|
||||
Set.singleton name
|
||||
|
||||
|
||||
addExposedVariables : Context -> Ast.Statement.ExportSet -> Context
|
||||
addExposedVariables ctx exportType =
|
||||
{ ctx
|
||||
| scopes =
|
||||
getExported exportType
|
||||
|> Set.toList
|
||||
|> addUsedToStack ctx.scopes
|
||||
}
|
||||
|
||||
|
||||
statementFn : Context -> Direction Statement -> ( List LintError, Context )
|
||||
statementFn ctx node =
|
||||
case node of
|
||||
@ -198,6 +208,9 @@ statementFn ctx node =
|
||||
Enter (ModuleDeclaration names AllExport) ->
|
||||
( [], { ctx | exportsEverything = True } )
|
||||
|
||||
Enter (PortModuleDeclaration names AllExport) ->
|
||||
( [], { ctx | exportsEverything = True } )
|
||||
|
||||
Enter (ImportStatement module_ alias_ (Just (SubsetExport imported))) ->
|
||||
let
|
||||
variables =
|
||||
@ -216,14 +229,10 @@ statementFn ctx node =
|
||||
( [], { ctx | scopes = addFoundToStack ctx.scopes variables } )
|
||||
|
||||
Enter (ModuleDeclaration names exportType) ->
|
||||
( []
|
||||
, { ctx
|
||||
| scopes =
|
||||
getExported exportType
|
||||
|> Set.toList
|
||||
|> addUsedToStack ctx.scopes
|
||||
}
|
||||
)
|
||||
( [], addExposedVariables ctx exportType )
|
||||
|
||||
Enter (PortModuleDeclaration names exportType) ->
|
||||
( [], addExposedVariables ctx exportType )
|
||||
|
||||
_ ->
|
||||
( [], ctx )
|
||||
|
@ -59,6 +59,28 @@ tests =
|
||||
c = 3
|
||||
"""
|
||||
|> expectErrors [ error "Variable `c` is not used" ]
|
||||
, test "should not report unused top-level variables if everything is exposed (port module)" <|
|
||||
\() ->
|
||||
testRule """port module A exposing (..)
|
||||
a n = 1
|
||||
b = a 1
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report unused top-level variables that are exposed by name (port module)" <|
|
||||
\() ->
|
||||
testRule """port module A exposing (a, b)
|
||||
a = 1
|
||||
b = 2
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report unused top-level variables that are exposed by name, but report others (port module)" <|
|
||||
\() ->
|
||||
testRule """port module A exposing (a, b)
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
"""
|
||||
|> expectErrors [ error "Variable `c` is not used" ]
|
||||
, test "should report unused variables from let declarations" <|
|
||||
\() ->
|
||||
testRule """module A exposing (a)
|
||||
|
Loading…
Reference in New Issue
Block a user