mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05:35 +03:00
Refactor review function
This commit is contained in:
parent
0857393e35
commit
54291a9cf0
@ -489,16 +489,42 @@ to compare them or the model that holds them.
|
||||
-}
|
||||
reviewWithPrecollectionOfData : List Rule -> Maybe ProjectData -> Project -> { errors : List ReviewError, rules : List Rule, projectData : Maybe ProjectData }
|
||||
reviewWithPrecollectionOfData rules maybeProjectData project =
|
||||
checkForModulesThatFailedToParse project
|
||||
|> Result.andThen (\() -> checkForDuplicateModules project)
|
||||
|> Result.andThen (\() -> getModulesSortedByImport project)
|
||||
|> Result.map (runReview project rules maybeProjectData)
|
||||
|> Result.mapError
|
||||
(\errors ->
|
||||
{ errors = errors
|
||||
, rules = rules
|
||||
, projectData = maybeProjectData
|
||||
}
|
||||
)
|
||||
|> extractResultValue
|
||||
|
||||
|
||||
checkForModulesThatFailedToParse : Project -> Result (List ReviewError) ()
|
||||
checkForModulesThatFailedToParse project =
|
||||
case Review.Project.modulesThatFailedToParse project of
|
||||
[] ->
|
||||
Ok ()
|
||||
|
||||
modulesThatFailedToParse ->
|
||||
Err (List.map parsingError modulesThatFailedToParse)
|
||||
|
||||
|
||||
checkForDuplicateModules : Project -> Result (List ReviewError) ()
|
||||
checkForDuplicateModules project =
|
||||
case Review.Project.modules project |> duplicateModuleNames Dict.empty of
|
||||
Just duplicate ->
|
||||
{ errors = [ duplicateModulesGlobalError duplicate ]
|
||||
, rules = rules
|
||||
, projectData = Nothing
|
||||
}
|
||||
Err [ duplicateModulesGlobalError duplicate ]
|
||||
|
||||
Nothing ->
|
||||
Ok ()
|
||||
|
||||
|
||||
getModulesSortedByImport : Project -> Result (List Review.Error.ReviewError) (List (Graph.NodeContext ModuleName ()))
|
||||
getModulesSortedByImport project =
|
||||
let
|
||||
sortedModules : Result (Graph.Edge ()) (List (Graph.NodeContext ModuleName ()))
|
||||
sortedModules =
|
||||
@ -507,9 +533,8 @@ reviewWithPrecollectionOfData rules maybeProjectData project =
|
||||
|> Graph.checkAcyclic
|
||||
|> Result.map Graph.topologicalSort
|
||||
in
|
||||
case sortedModules of
|
||||
Err _ ->
|
||||
{ errors =
|
||||
Result.mapError
|
||||
(\_ ->
|
||||
[ Review.Error.ReviewError
|
||||
{ filePath = "GLOBAL ERROR"
|
||||
, ruleName = "Incorrect project"
|
||||
@ -522,11 +547,21 @@ reviewWithPrecollectionOfData rules maybeProjectData project =
|
||||
, target = Review.Error.Global
|
||||
}
|
||||
]
|
||||
, rules = rules
|
||||
, projectData = Nothing
|
||||
}
|
||||
)
|
||||
sortedModules
|
||||
|
||||
Ok nodeContexts ->
|
||||
|
||||
extractResultValue : Result a a -> a
|
||||
extractResultValue result =
|
||||
case result of
|
||||
Ok a ->
|
||||
a
|
||||
|
||||
Err a ->
|
||||
a
|
||||
|
||||
|
||||
runReview project rules maybeProjectData nodeContexts =
|
||||
let
|
||||
scopeCache : Maybe (ProjectRuleCache ScopeProjectContext)
|
||||
scopeCache =
|
||||
@ -580,12 +615,6 @@ reviewWithPrecollectionOfData rules maybeProjectData project =
|
||||
, projectData = Just (ProjectData scopeResult.cache)
|
||||
}
|
||||
|
||||
modulesThatFailedToParse ->
|
||||
{ errors = List.map parsingError modulesThatFailedToParse
|
||||
, rules = rules
|
||||
, projectData = Nothing
|
||||
}
|
||||
|
||||
|
||||
type ProjectData
|
||||
= ProjectData (ProjectRuleCache ScopeProjectContext)
|
||||
|
Loading…
Reference in New Issue
Block a user