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
@ -68,7 +68,7 @@ Also, if you like comparing custom types in the way described above, you might p
|
||||
You can try this rule out by running the following command:
|
||||
|
||||
```bash
|
||||
elm - review --template jfmengels/elm-review-unused/example --rules NoUnused.CustomTypeConstructorArgs
|
||||
elm-review --template jfmengels/elm-review-unused/example --rules NoUnused.CustomTypeConstructorArgs
|
||||
```
|
||||
|
||||
-}
|
||||
@ -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 } )
|
||||
|
||||
|
@ -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 } }
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
|
@ -81,7 +81,8 @@ moduleVisitor schema =
|
||||
type alias ProjectContext =
|
||||
{ projectType : ProjectType
|
||||
, modules :
|
||||
Dict ModuleName
|
||||
Dict
|
||||
ModuleName
|
||||
{ moduleKey : Rule.ModuleKey
|
||||
, exposed : Dict String ExposedElement
|
||||
}
|
||||
|
@ -74,7 +74,8 @@ moduleVisitor schema =
|
||||
|
||||
type alias ProjectContext =
|
||||
{ modules :
|
||||
Dict ModuleName
|
||||
Dict
|
||||
ModuleName
|
||||
{ moduleKey : Rule.ModuleKey
|
||||
, moduleNameLocation : Range
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user