mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05:35 +03:00
Add ModuleNameLookupTable
This commit is contained in:
parent
f32dc336af
commit
494d376ba6
@ -4,6 +4,7 @@ module Review.Project exposing
|
||||
, addElmJson, elmJson
|
||||
, addReadme, readme
|
||||
, addDependency, removeDependencies, dependencies
|
||||
, ModuleNameLookupTable
|
||||
)
|
||||
|
||||
{-| Represents the contents of the project to be analyzed. This information will
|
||||
@ -75,9 +76,14 @@ new =
|
||||
, dependencies = Dict.empty
|
||||
, moduleGraph = Nothing
|
||||
, sourceDirectories = [ "src/" ]
|
||||
, moduleNameLookupTables = Dict.empty
|
||||
}
|
||||
|
||||
|
||||
type alias ModuleNameLookupTable =
|
||||
Internal.ModuleNameLookupTable
|
||||
|
||||
|
||||
|
||||
-- PROJECT FILES
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Review.Project.Internal exposing
|
||||
( Project(..)
|
||||
( ModuleNameLookupTable
|
||||
, Project(..)
|
||||
, ProjectModule
|
||||
, buildModuleGraph
|
||||
, moduleGraph
|
||||
@ -29,6 +30,7 @@ type Project
|
||||
, dependencies : Dict String Dependency
|
||||
, moduleGraph : Maybe (Graph ModuleName ())
|
||||
, sourceDirectories : List String
|
||||
, moduleNameLookupTables : Dict String ModuleNameLookupTable
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +44,10 @@ type alias ProjectModule =
|
||||
}
|
||||
|
||||
|
||||
type alias ModuleNameLookupTable =
|
||||
()
|
||||
|
||||
|
||||
{-| Get the module graph for the project in the form of a
|
||||
[`elm-community/graph` Graph]. This is used by `Review.Rule` internally.
|
||||
|
||||
|
@ -17,6 +17,7 @@ module Review.Rule exposing
|
||||
, ignoreErrorsForDirectories, ignoreErrorsForFiles
|
||||
, review, ruleName
|
||||
, Required, Forbidden
|
||||
, withModuleNameLookupTable
|
||||
)
|
||||
|
||||
{-| This module contains functions that are used for writing rules.
|
||||
@ -265,7 +266,7 @@ import Elm.Syntax.Range as Range exposing (Range)
|
||||
import Review.Error exposing (InternalError)
|
||||
import Review.Exceptions as Exceptions exposing (Exceptions)
|
||||
import Review.Fix exposing (Fix)
|
||||
import Review.Project exposing (Project, ProjectModule)
|
||||
import Review.Project exposing (ModuleNameLookupTable, Project, ProjectModule)
|
||||
import Review.Project.Dependency
|
||||
import Review.Project.Internal
|
||||
import Set exposing (Set)
|
||||
@ -3771,6 +3772,7 @@ type ContextCreator from to
|
||||
type RequestedData
|
||||
= RequestedData
|
||||
{ metadata : Bool
|
||||
, moduleNameLookupTable : Bool
|
||||
}
|
||||
|
||||
|
||||
@ -3793,7 +3795,11 @@ initContextCreator fromProjectToModule =
|
||||
-- TODO Try to get rid of the ()/from when using in a module rule
|
||||
ContextCreator
|
||||
(always fromProjectToModule)
|
||||
(RequestedData { metadata = False })
|
||||
(RequestedData
|
||||
{ metadata = False
|
||||
, moduleNameLookupTable = False
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
applyContextCreator : AvailableData -> ContextCreator from to -> from -> to
|
||||
@ -3824,6 +3830,13 @@ withMetadata (ContextCreator fn (RequestedData requested)) =
|
||||
(RequestedData { requested | metadata = True })
|
||||
|
||||
|
||||
withModuleNameLookupTable : ContextCreator ModuleNameLookupTable (from -> to) -> ContextCreator from to
|
||||
withModuleNameLookupTable (ContextCreator fn (RequestedData requested)) =
|
||||
ContextCreator
|
||||
(\data -> fn data ())
|
||||
(RequestedData { requested | moduleNameLookupTable = True })
|
||||
|
||||
|
||||
{-| Request the [module key](ModuleKey) for this module.
|
||||
|
||||
rule =
|
||||
|
@ -2,6 +2,7 @@ module MiscRules.NoHtmlButton exposing (rule)
|
||||
|
||||
import Elm.Syntax.Expression exposing (Expression(..))
|
||||
import Elm.Syntax.Node as Node exposing (Node)
|
||||
import Review.Project exposing (ModuleNameLookupTable)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
import Scope
|
||||
|
||||
@ -16,25 +17,22 @@ rule =
|
||||
|> Rule.ignoreErrorsForFiles [ "src/Button.elm" ]
|
||||
|
||||
|
||||
type alias NewScope =
|
||||
()
|
||||
|
||||
|
||||
type alias Context =
|
||||
-- Scope expects a context with a record, containing the `scope` field.
|
||||
{ scope : Scope.ModuleContext
|
||||
, newScope : NewScope
|
||||
, moduleNameLookupTable : ModuleNameLookupTable
|
||||
}
|
||||
|
||||
|
||||
contextCreator : Rule.ContextCreator () Context
|
||||
contextCreator =
|
||||
Rule.initContextCreator
|
||||
(\() ->
|
||||
(\moduleNameLookupTable () ->
|
||||
{ scope = Scope.initialModuleContext
|
||||
, newScope = ()
|
||||
, moduleNameLookupTable = moduleNameLookupTable
|
||||
}
|
||||
)
|
||||
|> Rule.withModuleNameLookupTable
|
||||
|
||||
|
||||
expressionVisitor : Node Expression -> Context -> ( List (Error {}), Context )
|
||||
|
Loading…
Reference in New Issue
Block a user