mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Rename realFunctionOrType by realModuleName
This commit is contained in:
parent
9328872aa6
commit
143ecb9618
@ -52,7 +52,7 @@ expressionVisitor node direction context =
|
||||
( Rule.OnEnter, HtmlButtonIsForbidden ) ->
|
||||
case Node.value node of
|
||||
FunctionOrValue moduleName name ->
|
||||
if Scope.realFunctionOrType moduleName name context.scope == ( [ "Html" ], "button" ) then
|
||||
if name == "button" && Scope.realModuleName moduleName name context.scope == [ "Html" ] then
|
||||
( [ Rule.error
|
||||
{ message = "Do not use `Html.button` directly"
|
||||
, details = [ "At fruits.com, we've built a nice `Button` module that suits our needs better. Using this module instead of `Html.button` ensures we have a consistent button experience across the website." ]
|
||||
|
@ -426,8 +426,7 @@ registerUsedFunctionOrValue moduleName name moduleContext =
|
||||
let
|
||||
realModuleName : ModuleName
|
||||
realModuleName =
|
||||
Scope.realFunctionOrType moduleName name moduleContext.scope
|
||||
|> Tuple.first
|
||||
Scope.realModuleName moduleName name moduleContext.scope
|
||||
in
|
||||
{ moduleContext
|
||||
| usedFunctionsOrValues =
|
||||
@ -580,8 +579,7 @@ collectTypesUsedAsPhantomVariables scope phantomVariables node =
|
||||
let
|
||||
realModuleNameOfPhantomContainer : ModuleName
|
||||
realModuleNameOfPhantomContainer =
|
||||
Scope.realFunctionOrType moduleNameOfPhantomContainer name scope
|
||||
|> Tuple.first
|
||||
Scope.realModuleName moduleNameOfPhantomContainer name scope
|
||||
|
||||
typesUsedInThePhantomVariablePosition : List ( ModuleName, CustomTypeName )
|
||||
typesUsedInThePhantomVariablePosition =
|
||||
@ -592,8 +590,7 @@ collectTypesUsedAsPhantomVariables scope phantomVariables node =
|
||||
(\( _, index ) ->
|
||||
case listAtIndex index params |> Maybe.map Node.value of
|
||||
Just (TypeAnnotation.Typed (Node.Node _ ( moduleNameOfPhantomVariable, typeName )) _) ->
|
||||
Just <|
|
||||
Scope.realFunctionOrType moduleNameOfPhantomVariable typeName scope
|
||||
Just ( Scope.realModuleName moduleNameOfPhantomVariable typeName scope, typeName )
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
@ -407,16 +407,15 @@ testFunctionName scope declaration =
|
||||
|> Maybe.map (Node.value >> .typeAnnotation >> Node.value)
|
||||
of
|
||||
Just (TypeAnnotation.Typed (Node _ ( moduleName, name )) _) ->
|
||||
case Scope.realFunctionOrType moduleName name scope of
|
||||
( [ "Test" ], "Test" ) ->
|
||||
function.declaration
|
||||
|> Node.value
|
||||
|> .name
|
||||
|> Node.value
|
||||
|> Just
|
||||
if name == "Test" && Scope.realModuleName moduleName name scope == [ "Test" ] then
|
||||
function.declaration
|
||||
|> Node.value
|
||||
|> .name
|
||||
|> Node.value
|
||||
|> Just
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
else
|
||||
Nothing
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
@ -468,7 +467,7 @@ collectTypesFromTypeAnnotation scope node =
|
||||
collectTypesFromTypeAnnotation scope a ++ collectTypesFromTypeAnnotation scope b
|
||||
|
||||
TypeAnnotation.Typed (Node _ ( moduleName, name )) params ->
|
||||
Scope.realFunctionOrType moduleName name scope
|
||||
( Scope.realModuleName moduleName name scope, name )
|
||||
:: List.concatMap (collectTypesFromTypeAnnotation scope) params
|
||||
|
||||
TypeAnnotation.Record list ->
|
||||
@ -502,7 +501,7 @@ expressionVisitor node direction moduleContext =
|
||||
( Rule.OnEnter, Expression.FunctionOrValue moduleName name ) ->
|
||||
( []
|
||||
, registerAsUsed
|
||||
(Scope.realFunctionOrType moduleName name moduleContext.scope)
|
||||
( Scope.realModuleName moduleName name moduleContext.scope, name )
|
||||
moduleContext
|
||||
)
|
||||
|
||||
|
@ -2,7 +2,7 @@ module Review.Scope exposing
|
||||
( ModuleContext, addModuleVisitors, initialModuleContext
|
||||
, ProjectContext, addProjectVisitors
|
||||
, initialProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts
|
||||
, realFunctionOrType
|
||||
, realModuleName
|
||||
)
|
||||
|
||||
{-| Collect and infer information automatically for you
|
||||
@ -21,7 +21,7 @@ module Review.Scope exposing
|
||||
|
||||
# Access
|
||||
|
||||
@docs realFunctionOrType
|
||||
@docs realModuleName
|
||||
|
||||
-}
|
||||
|
||||
@ -209,30 +209,6 @@ internalAddModuleVisitors schema =
|
||||
)
|
||||
|
||||
|
||||
|
||||
-- scopedRule :
|
||||
-- String
|
||||
-- ->
|
||||
-- { forGlobal :
|
||||
-- { get : projectContext -> ProjectContext
|
||||
-- , set : ProjectContext -> projectContext -> projectContext
|
||||
-- }
|
||||
-- , forModule :
|
||||
-- { get : moduleContext -> ModuleContext
|
||||
-- , set : ModuleContext -> moduleContext -> moduleContext
|
||||
-- }
|
||||
-- }
|
||||
-- ->
|
||||
-- { moduleVisitor : Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasNoVisitor : () } moduleContext -> Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasAtLeastOneVisitor : () } moduleContext
|
||||
-- , fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> projectContext -> moduleContext
|
||||
-- , fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
-- , foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
-- }
|
||||
-- -> Rule.ProjectRuleSchema projectContext moduleContext
|
||||
-- scopedRule name setterGetters context =
|
||||
-- Rule.newProjectRuleSchema name
|
||||
|
||||
|
||||
mapInnerProjectContext : (visitedElement -> InnerProjectContext -> InnerProjectContext) -> visitedElement -> { projectContext | scope : ProjectContext } -> ( List nothing, { projectContext | scope : ProjectContext } )
|
||||
mapInnerProjectContext visitor visitedElement outerContext =
|
||||
let
|
||||
@ -687,7 +663,6 @@ registerImportExposed import_ innerContext =
|
||||
exposedValues : Dict String (List String)
|
||||
exposedValues =
|
||||
topLevelExposeList
|
||||
-- TODO HERE We notice that the module has no tags or union, even though it should
|
||||
|> List.concatMap (namesFromExposingList module_)
|
||||
|> List.map (\name -> ( name, moduleName ))
|
||||
|> Dict.fromList
|
||||
@ -939,26 +914,22 @@ findInList predicate list =
|
||||
-- ACCESS
|
||||
|
||||
|
||||
realFunctionOrType : List String -> String -> ModuleContext -> ( List String, String )
|
||||
realFunctionOrType moduleName functionOrType (ModuleContext context) =
|
||||
realModuleName : List String -> String -> ModuleContext -> List String
|
||||
realModuleName moduleName functionOrType (ModuleContext context) =
|
||||
if List.length moduleName == 0 then
|
||||
( if isInScope functionOrType context.scopes then
|
||||
if isInScope functionOrType context.scopes then
|
||||
[]
|
||||
|
||||
else
|
||||
else
|
||||
Dict.get functionOrType context.importedFunctionOrTypes
|
||||
|> Maybe.withDefault []
|
||||
, functionOrType
|
||||
)
|
||||
|
||||
else if List.length moduleName == 1 then
|
||||
( Dict.get (getModuleName moduleName) context.importAliases
|
||||
Dict.get (getModuleName moduleName) context.importAliases
|
||||
|> Maybe.withDefault moduleName
|
||||
, functionOrType
|
||||
)
|
||||
|
||||
else
|
||||
( moduleName, functionOrType )
|
||||
moduleName
|
||||
|
||||
|
||||
isInScope : String -> Nonempty Scope -> Bool
|
||||
|
@ -15,14 +15,14 @@ import Test exposing (Test, test)
|
||||
all : Test
|
||||
all =
|
||||
Test.describe "Scope"
|
||||
[ realFunctionOrTypeTestsForModuleRule
|
||||
, realFunctionOrTypeTestsForProjectRule
|
||||
[ realModuleNameTestsForModuleRule
|
||||
, realModuleNameTestsForProjectRule
|
||||
]
|
||||
|
||||
|
||||
realFunctionOrTypeTestsForModuleRule : Test
|
||||
realFunctionOrTypeTestsForModuleRule =
|
||||
Test.describe "Scope.realFunctionOrType (module rule)"
|
||||
realModuleNameTestsForModuleRule : Test
|
||||
realModuleNameTestsForModuleRule =
|
||||
Test.describe "Scope.realModuleName (module rule)"
|
||||
[ test "should indicate that module from which a function or value comes from, with knowledge of what is in other modules" <|
|
||||
\() ->
|
||||
"""module A exposing (..)
|
||||
@ -84,9 +84,9 @@ Http.get -> Http.get
|
||||
]
|
||||
|
||||
|
||||
realFunctionOrTypeTestsForProjectRule : Test
|
||||
realFunctionOrTypeTestsForProjectRule =
|
||||
Test.describe "Scope.realFunctionOrType (project rule)"
|
||||
realModuleNameTestsForProjectRule : Test
|
||||
realModuleNameTestsForProjectRule =
|
||||
Test.describe "Scope.realModuleName (project rule)"
|
||||
[ test "should indicate that module from which a function or value comes from, with knowledge of what is in other modules" <|
|
||||
\() ->
|
||||
[ """module A exposing (..)
|
||||
@ -260,12 +260,12 @@ typeAnnotationNames scope typeAnnotation =
|
||||
|
||||
realName : String
|
||||
realName =
|
||||
case Scope.realFunctionOrType moduleName typeName scope of
|
||||
( [], name_ ) ->
|
||||
"<nothing>." ++ name_
|
||||
case Scope.realModuleName moduleName typeName scope of
|
||||
[] ->
|
||||
"<nothing>." ++ typeName
|
||||
|
||||
( moduleName_, name_ ) ->
|
||||
String.join "." moduleName_ ++ "." ++ name_
|
||||
moduleName_ ->
|
||||
String.join "." moduleName_ ++ "." ++ typeName
|
||||
in
|
||||
nameInCode ++ " -> " ++ realName
|
||||
|
||||
@ -301,12 +301,12 @@ expressionVisitor node direction context =
|
||||
|
||||
realName : String
|
||||
realName =
|
||||
case Scope.realFunctionOrType moduleName name context.scope of
|
||||
( [], name_ ) ->
|
||||
"<nothing>." ++ name_
|
||||
case Scope.realModuleName moduleName name context.scope of
|
||||
[] ->
|
||||
"<nothing>." ++ name
|
||||
|
||||
( moduleName_, name_ ) ->
|
||||
String.join "." moduleName_ ++ "." ++ name_
|
||||
moduleName_ ->
|
||||
String.join "." moduleName_ ++ "." ++ name
|
||||
in
|
||||
( [], { context | text = context.text ++ "\n" ++ nameInCode ++ " -> " ++ realName } )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user