Backport elm-review-unused

This commit is contained in:
Jeroen Engels 2020-12-05 12:40:40 +01:00
parent dd1ffc5266
commit c6ca7ec9fe
4 changed files with 51 additions and 5 deletions

View File

@ -89,7 +89,8 @@ rule =
type alias ProjectContext =
{ exposedModules : Set ModuleName
, customTypeArgs :
Dict ModuleName
Dict
ModuleName
{ moduleKey : Rule.ModuleKey
, args : Dict String (List Range)
}
@ -328,7 +329,8 @@ expressionVisitor node context =
let
usedArguments : List ( ( ModuleName, String ), Set Int )
usedArguments =
List.concatMap (Tuple.first >> collectUsedCustomTypeArgs context.lookupTable) cases
cases
|> List.concatMap (Tuple.first >> collectUsedCustomTypeArgs context.lookupTable)
in
( [], { context | usedArguments = registerUsedPatterns usedArguments context.usedArguments } )

View File

@ -594,4 +594,46 @@ foo = [ (Foo, A), (Bar, B) ]
]
|> Review.Test.runOnModulesWithProjectData project (rule [])
|> Review.Test.expectNoErrors
, test "should not report imported type constructors when they are shadowed by a local type alias that does not create a function (#5)" <|
\() ->
[ """module A exposing (x)
import B exposing (Foo(..))
type alias Foo = B.Foo -- this "shadowing" is causing the bug, removing the alias removes the false positive
x = Foo 1 -- usage of the custom type constructor!
"""
, """module B exposing (Foo(..))
type Foo = Foo Int
"""
]
|> Review.Test.runOnModulesWithProjectData project (rule [])
|> Review.Test.expectNoErrors
, test "should report imported type constructors even when they are shadowed by a local type alias that creates a function (#5)" <|
\() ->
[ """module A exposing (x)
import B exposing (Foo(..))
type alias Foo = { n : Int }
x = Foo 1 -- Not a usage of B.Foo in this case!
"""
, """module B exposing (Foo(..))
type Foo = Foo Int
"""
]
|> Review.Test.runOnModulesWithProjectData project (rule [])
|> Review.Test.expectErrorsForModules
[ ( "B"
, [ Review.Test.error
{ message = "Type constructor `Foo` is not used."
, details = details
, under = "Foo"
}
|> Review.Test.atExactly { start = { row = 2, column = 12 }, end = { row = 2, column = 15 } }
]
)
]
]

View File

@ -81,7 +81,8 @@ moduleVisitor schema =
type alias ProjectContext =
{ projectType : ProjectType
, modules :
Dict ModuleName
Dict
ModuleName
{ moduleKey : Rule.ModuleKey
, exposed : Dict String ExposedElement
}

View File

@ -74,7 +74,8 @@ moduleVisitor schema =
type alias ProjectContext =
{ modules :
Dict ModuleName
Dict
ModuleName
{ moduleKey : Rule.ModuleKey
, moduleNameLocation : Range
}