From c65f383acdc9abe4d1ae2119932c57716807a439 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 30 Nov 2024 18:47:59 +0100 Subject: [PATCH] Extract function --- src/Review/Rule.elm | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index 2baeb31b..b4fb6b45 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -5847,24 +5847,10 @@ findFixHelp project fixablePredicate errors accErrors maybeModuleZipper = firstFix :: restOfFixes -> let - applyFixes : List ( Review.Error.Target, List InternalFix.Fix ) -> { project : ValidProject, fixedFile : FixedFile } -> Result (Error {}) { project : ValidProject, fixedFile : FixedFile } - applyFixes fixes acc = - case fixes of - [] -> - Ok acc - - fix :: rest -> - case applyFix acc.project maybeModuleZipper err fix of - Ok fixResult -> - applyFixes rest { project = fixResult.project, fixedFile = earlierFixedFile fixResult.fixedFile acc.fixedFile } - - fixResultErr -> - fixResultErr - appliedFixes : Result (Error {}) { project : ValidProject, fixedFile : FixedFile } appliedFixes = applyFix project maybeModuleZipper err firstFix - |> Result.andThen (\fixResult -> applyFixes restOfFixes fixResult) + |> Result.andThen (\fixResult -> applyFixes maybeModuleZipper err restOfFixes fixResult) in case appliedFixes of Ok fixResult -> @@ -5874,6 +5860,21 @@ findFixHelp project fixablePredicate errors accErrors maybeModuleZipper = findFixHelp project fixablePredicate restOfErrors (nonAppliedError :: accErrors) maybeModuleZipper +applyFixes : Maybe (Zipper (Graph.NodeContext FilePath ())) -> Error {} -> List ( Review.Error.Target, List InternalFix.Fix ) -> { project : ValidProject, fixedFile : FixedFile } -> Result (Error {}) { project : ValidProject, fixedFile : FixedFile } +applyFixes maybeModuleZipper err fixes acc = + case fixes of + [] -> + Ok acc + + fix :: rest -> + case applyFix acc.project maybeModuleZipper err fix of + Ok fixResult -> + applyFixes maybeModuleZipper err rest { project = fixResult.project, fixedFile = earlierFixedFile fixResult.fixedFile acc.fixedFile } + + fixResultErr -> + fixResultErr + + earlierFixedFile : FixedFile -> FixedFile -> FixedFile earlierFixedFile a b = case ( a, b ) of