mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-09-11 16:16:09 +03:00
Add elm.json visitor to get the version
This commit is contained in:
parent
51579cf373
commit
af23bbaf73
@ -6,8 +6,8 @@ module Docs.NoMissingChangelogEntry exposing (rule)
|
||||
|
||||
-}
|
||||
|
||||
import Elm.Syntax.Expression exposing (Expression)
|
||||
import Elm.Syntax.Node as Node exposing (Node)
|
||||
import Elm.Project exposing (Project)
|
||||
import Elm.Version
|
||||
import Review.Rule as Rule exposing (Rule)
|
||||
|
||||
|
||||
@ -48,59 +48,32 @@ elm-review --template jfmengels/elm-review/example --rules Docs.NoMissingChangel
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "Docs.NoMissingChangelogEntry" initialProjectContext
|
||||
|> Rule.withModuleVisitor moduleVisitor
|
||||
|> Rule.withModuleContextUsingContextCreator
|
||||
{ fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
}
|
||||
-- Enable this if modules need to get information from other modules
|
||||
-- |> Rule.withContextFromImportedModules
|
||||
|> Rule.withElmJsonProjectVisitor elmJsonVisitor
|
||||
|> Rule.fromProjectRuleSchema
|
||||
|
||||
|
||||
type alias ProjectContext =
|
||||
{}
|
||||
|
||||
|
||||
type alias ModuleContext =
|
||||
{}
|
||||
|
||||
|
||||
moduleVisitor : Rule.ModuleRuleSchema schema ModuleContext -> Rule.ModuleRuleSchema { schema | hasAtLeastOneVisitor : () } ModuleContext
|
||||
moduleVisitor schema =
|
||||
schema
|
||||
|> Rule.withExpressionEnterVisitor expressionVisitor
|
||||
{ elmJsonVersion : String
|
||||
}
|
||||
|
||||
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{}
|
||||
{ elmJsonVersion = "1.0.0"
|
||||
}
|
||||
|
||||
|
||||
fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
|
||||
fromProjectToModule =
|
||||
Rule.initContextCreator
|
||||
(\projectContext ->
|
||||
{}
|
||||
)
|
||||
elmJsonVisitor : Maybe { a | project : Project } -> ProjectContext -> ( List nothing, ProjectContext )
|
||||
elmJsonVisitor maybeElmJsonData context =
|
||||
case maybeElmJsonData of
|
||||
Just { project } ->
|
||||
case project of
|
||||
Elm.Project.Package { version } ->
|
||||
( [], { context | elmJsonVersion = Elm.Version.toString version } )
|
||||
|
||||
Elm.Project.Application _ ->
|
||||
-- TODO Report an error
|
||||
( [], context )
|
||||
|
||||
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
|
||||
fromModuleToProject =
|
||||
Rule.initContextCreator
|
||||
(\moduleContext ->
|
||||
{}
|
||||
)
|
||||
|
||||
|
||||
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext
|
||||
foldProjectContexts new previous =
|
||||
{}
|
||||
|
||||
|
||||
expressionVisitor : Node Expression -> ProjectContext -> ( List (Rule.Error {}), ProjectContext )
|
||||
expressionVisitor node context =
|
||||
case Node.value node of
|
||||
_ ->
|
||||
Nothing ->
|
||||
( [], context )
|
||||
|
Loading…
Reference in New Issue
Block a user