Skip to content

Commit

Permalink
Extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Nov 30, 2024
1 parent 0a29356 commit c65f383
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/Review/Rule.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit c65f383

Please sign in to comment.