mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Backport elm-review-unused
This commit is contained in:
parent
dd1ffc5266
commit
c6ca7ec9fe
@ -89,7 +89,8 @@ rule =
|
|||||||
type alias ProjectContext =
|
type alias ProjectContext =
|
||||||
{ exposedModules : Set ModuleName
|
{ exposedModules : Set ModuleName
|
||||||
, customTypeArgs :
|
, customTypeArgs :
|
||||||
Dict ModuleName
|
Dict
|
||||||
|
ModuleName
|
||||||
{ moduleKey : Rule.ModuleKey
|
{ moduleKey : Rule.ModuleKey
|
||||||
, args : Dict String (List Range)
|
, args : Dict String (List Range)
|
||||||
}
|
}
|
||||||
@ -328,7 +329,8 @@ expressionVisitor node context =
|
|||||||
let
|
let
|
||||||
usedArguments : List ( ( ModuleName, String ), Set Int )
|
usedArguments : List ( ( ModuleName, String ), Set Int )
|
||||||
usedArguments =
|
usedArguments =
|
||||||
List.concatMap (Tuple.first >> collectUsedCustomTypeArgs context.lookupTable) cases
|
cases
|
||||||
|
|> List.concatMap (Tuple.first >> collectUsedCustomTypeArgs context.lookupTable)
|
||||||
in
|
in
|
||||||
( [], { context | usedArguments = registerUsedPatterns usedArguments context.usedArguments } )
|
( [], { context | usedArguments = registerUsedPatterns usedArguments context.usedArguments } )
|
||||||
|
|
||||||
|
@ -594,4 +594,46 @@ foo = [ (Foo, A), (Bar, B) ]
|
|||||||
]
|
]
|
||||||
|> Review.Test.runOnModulesWithProjectData project (rule [])
|
|> Review.Test.runOnModulesWithProjectData project (rule [])
|
||||||
|> Review.Test.expectNoErrors
|
|> 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 } }
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
@ -81,7 +81,8 @@ moduleVisitor schema =
|
|||||||
type alias ProjectContext =
|
type alias ProjectContext =
|
||||||
{ projectType : ProjectType
|
{ projectType : ProjectType
|
||||||
, modules :
|
, modules :
|
||||||
Dict ModuleName
|
Dict
|
||||||
|
ModuleName
|
||||||
{ moduleKey : Rule.ModuleKey
|
{ moduleKey : Rule.ModuleKey
|
||||||
, exposed : Dict String ExposedElement
|
, exposed : Dict String ExposedElement
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,8 @@ moduleVisitor schema =
|
|||||||
|
|
||||||
type alias ProjectContext =
|
type alias ProjectContext =
|
||||||
{ modules :
|
{ modules :
|
||||||
Dict ModuleName
|
Dict
|
||||||
|
ModuleName
|
||||||
{ moduleKey : Rule.ModuleKey
|
{ moduleKey : Rule.ModuleKey
|
||||||
, moduleNameLocation : Range
|
, moduleNameLocation : Range
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user