mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-09-11 16:16:09 +03:00
Apply fixes for extra files
This commit is contained in:
parent
b00b58cf1e
commit
3c1107df56
@ -1,4 +1,4 @@
|
||||
module Review.Fix.Internal exposing (Fix(..), applyFix, containRangeCollisions, fixElmJson, fixModule, fixReadme, rangePosition)
|
||||
module Review.Fix.Internal exposing (Fix(..), applyFix, containRangeCollisions, fixElmJson, fixExtraFile, fixModule, fixReadme, rangePosition)
|
||||
|
||||
import Array
|
||||
import Elm.Project
|
||||
@ -124,6 +124,13 @@ fixReadme fixes originalSourceCode =
|
||||
tryToApplyFix fixes originalSourceCode
|
||||
|
||||
|
||||
{-| Apply the changes on an extra file.
|
||||
-}
|
||||
fixExtraFile : List Fix -> String -> Result FixProblem.FixProblem String
|
||||
fixExtraFile fixes originalSourceCode =
|
||||
tryToApplyFix fixes originalSourceCode
|
||||
|
||||
|
||||
tryToApplyFix : List Fix -> String -> Result FixProblem.FixProblem String
|
||||
tryToApplyFix fixes sourceCode =
|
||||
if containRangeCollisions fixes then
|
||||
|
@ -344,6 +344,7 @@ import Review.Project.Valid as ValidProject exposing (ValidProject)
|
||||
import Review.RequestedData as RequestedData exposing (RequestedData(..))
|
||||
import Vendor.Graph as Graph exposing (Graph)
|
||||
import Vendor.IntDict as IntDict
|
||||
import Vendor.ListExtra as ListExtra
|
||||
import Vendor.Zipper as Zipper exposing (Zipper)
|
||||
|
||||
|
||||
@ -5459,7 +5460,22 @@ findFixHelp project fixablePredicate errors accErrors maybeModuleZipper =
|
||||
}
|
||||
|
||||
Review.Error.ExtraFile ->
|
||||
findFixHelp project fixablePredicate restOfErrors (err :: accErrors) maybeModuleZipper
|
||||
case ListExtra.find (\file -> file.path == headError.filePath) (ValidProject.extraFiles project) of
|
||||
Nothing ->
|
||||
findFixHelp project fixablePredicate restOfErrors (err :: accErrors) maybeModuleZipper
|
||||
|
||||
Just file ->
|
||||
case InternalFix.fixExtraFile fixes file.content of
|
||||
Err fixProblem ->
|
||||
findFixHelp project fixablePredicate restOfErrors (Error (Review.Error.markFixesAsProblem fixProblem headError) :: accErrors) maybeModuleZipper
|
||||
|
||||
Ok newFileContent ->
|
||||
FoundFixHelp
|
||||
(errors ++ accErrors)
|
||||
{ project = ValidProject.addExtraFile { path = headError.filePath, content = newFileContent } project
|
||||
, fixedFile = FixedExtraFile
|
||||
, error = errorToReviewError (Error headError)
|
||||
}
|
||||
|
||||
Review.Error.Global ->
|
||||
findFixHelp project fixablePredicate restOfErrors (err :: accErrors) maybeModuleZipper
|
||||
|
Loading…
Reference in New Issue
Block a user