mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Add ModuleNameLookupTable support for operators (#106)
This commit is contained in:
parent
8c8e708403
commit
2a8dbaf2a1
@ -33,11 +33,13 @@ type alias ModuleNameLookupTable =
|
||||
Internal.ModuleNameLookupTable
|
||||
|
||||
|
||||
{-| Returns the name of the module the type or value referred to by this [`Node`](https://package.elm-lang.org/packages/stil4m/elm-syntax/7.2.1/Elm-Syntax-Node#Node).
|
||||
{-| Returns the name of the module the type, value, or operator referred to by this [`Node`](https://package.elm-lang.org/packages/stil4m/elm-syntax/7.2.1/Elm-Syntax-Node#Node) was defined in.
|
||||
|
||||
The function returns `Just []` if the type or value was defined in this module. It returns `Just moduleName` if the Node is among these kinds of AST nodes (and `Nothing` for all the others):
|
||||
|
||||
- `Expression.FunctionOrValue`
|
||||
- `Expression.PrefixOperator`
|
||||
- `Expression.OperatorApplication`
|
||||
- `nodeForTheName` in `Expression.RecordUpdateExpression nodeForTheName modifiers`
|
||||
- `nodeForTheName` in `TypeAnnotation.Typed nodeForTheName args`
|
||||
- `Pattern.NamedPattern`
|
||||
|
@ -5278,7 +5278,7 @@ registerImportExposed import_ innerContext =
|
||||
|> Dict.fromList
|
||||
in
|
||||
{ innerContext
|
||||
| importedFunctions = Dict.union innerContext.importedFunctions exposedValues
|
||||
| importedFunctions = Dict.union exposedValues innerContext.importedFunctions
|
||||
, importedTypes = Dict.union innerContext.importedTypes exposedTypes
|
||||
}
|
||||
|
||||
@ -5299,7 +5299,7 @@ registerImportExposed import_ innerContext =
|
||||
|> Dict.fromList
|
||||
in
|
||||
{ innerContext
|
||||
| importedFunctions = Dict.union innerContext.importedFunctions exposedValues
|
||||
| importedFunctions = Dict.union exposedValues innerContext.importedFunctions
|
||||
, importedTypes = Dict.union innerContext.importedTypes exposedTypes
|
||||
}
|
||||
|
||||
@ -5659,6 +5659,24 @@ scope_expressionEnterVisitor node context =
|
||||
context.lookupTable
|
||||
}
|
||||
|
||||
Expression.PrefixOperator op ->
|
||||
{ context
|
||||
| lookupTable =
|
||||
ModuleNameLookupTableInternal.add
|
||||
(Node.range node)
|
||||
(moduleNameForValue context op [])
|
||||
context.lookupTable
|
||||
}
|
||||
|
||||
Expression.OperatorApplication op _ _ _ ->
|
||||
{ context
|
||||
| lookupTable =
|
||||
ModuleNameLookupTableInternal.add
|
||||
(Node.range node)
|
||||
(moduleNameForValue context op [])
|
||||
context.lookupTable
|
||||
}
|
||||
|
||||
_ ->
|
||||
context
|
||||
|
||||
|
@ -12,6 +12,7 @@ import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNam
|
||||
import Review.Project as Project exposing (Project)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
import Review.Test
|
||||
import Review.Test.Dependencies
|
||||
import Test exposing (Test, test)
|
||||
|
||||
|
||||
@ -38,6 +39,10 @@ import Html exposing (..)
|
||||
import Http exposing (get)
|
||||
import Something.B as Something
|
||||
import Something.C as Something
|
||||
import Url.Parser exposing (..)
|
||||
-- NOTE: The behavior of the compiler if duplicate infix operators are imported is for the second-imported one to overwrite the first.
|
||||
import Parser exposing ((|=))
|
||||
import Parser.Advanced exposing ((|=))
|
||||
|
||||
localValue = 1
|
||||
localValueValueToBeShadowed = 1
|
||||
@ -68,6 +73,12 @@ a = localValue
|
||||
True
|
||||
Just
|
||||
Cmd.none
|
||||
(+)
|
||||
(117 + 3)
|
||||
(<?>)
|
||||
("x" </> "y")
|
||||
(|=)
|
||||
("pars" |= "er")
|
||||
b = case () of
|
||||
VariantA -> ()
|
||||
(ExposesEverything.VariantA as foo) -> foo
|
||||
@ -124,6 +135,12 @@ Http.get -> Http.get
|
||||
<nothing>.True -> Basics.True
|
||||
<nothing>.Just -> Maybe.Just
|
||||
Cmd.none -> Platform.Cmd.none
|
||||
<nothing>.+ -> Basics.+
|
||||
<nothing>.+ -> Basics.+
|
||||
<nothing>.<?> -> Url.Parser.<?>
|
||||
<nothing>.</> -> Url.Parser.</>
|
||||
<nothing>.|= -> Parser.Advanced.|=
|
||||
<nothing>.|= -> Parser.Advanced.|=
|
||||
<nothing>.VariantA -> ExposesEverything.VariantA
|
||||
ExposesEverything.VariantA -> ExposesEverything.VariantA
|
||||
ExposesEverythingAlias.VariantA -> ExposesEverything.VariantA
|
||||
@ -212,6 +229,8 @@ project =
|
||||
Project.new
|
||||
|> Project.addDependency Dependencies.elmCore
|
||||
|> Project.addDependency Dependencies.elmHtml
|
||||
|> Project.addDependency Review.Test.Dependencies.elmParser
|
||||
|> Project.addDependency Review.Test.Dependencies.elmUrl
|
||||
|
||||
|
||||
createRule : (Rule.ModuleRuleSchema {} ModuleContext -> Rule.ModuleRuleSchema { hasAtLeastOneVisitor : () } ModuleContext) -> Rule
|
||||
@ -242,6 +261,12 @@ expressionVisitor node context =
|
||||
Expression.RecordUpdateExpression (Node range name) _ ->
|
||||
( [], { context | texts = context.texts ++ [ getRealName context [] range name ] } )
|
||||
|
||||
Expression.PrefixOperator op ->
|
||||
( [], { context | texts = context.texts ++ [ getRealName context [] (Node.range node) op ] } )
|
||||
|
||||
Expression.OperatorApplication op _ _ _ ->
|
||||
( [], { context | texts = context.texts ++ [ getRealName context [] (Node.range node) op ] } )
|
||||
|
||||
Expression.CaseExpression { cases } ->
|
||||
let
|
||||
texts : List String
|
||||
|
Loading…
Reference in New Issue
Block a user