mirror of
https://github.com/jfmengels/elm-review.git
synced 2025-01-08 10:47:25 +03:00
Change the API again
This commit is contained in:
parent
c8453f401e
commit
aa4589a36e
@ -2,6 +2,7 @@ module Review.Options exposing
|
||||
( ReviewOptions
|
||||
, defaults
|
||||
, withDataExtraction, withLogger, withFixes, withSuppressedErrors
|
||||
, FixMode, fixedDisabled, fixesEnabledWithLimit, fixesEnabledWithoutLimits
|
||||
)
|
||||
|
||||
{-| Configure how `elm-review` runs.
|
||||
@ -36,8 +37,7 @@ defaults =
|
||||
ReviewOptionsInternal
|
||||
{ extract = False
|
||||
, logger = Logger.none
|
||||
, fixes = Internal.Disabled
|
||||
, fixLimit = Nothing
|
||||
, fixMode = Internal.Disabled
|
||||
, suppressions = Dict.empty
|
||||
}
|
||||
|
||||
@ -65,23 +65,30 @@ withLogger maybeLogger (ReviewOptionsInternal reviewOptions) =
|
||||
}
|
||||
|
||||
|
||||
{-| Indicate whether to apply fixes, and if so, how many fixes should be applied before we abort the review process.
|
||||
|
||||
If the limit is `Nothing`, then all available fixes will be applied.
|
||||
|
||||
{-| Set the fix mode.
|
||||
-}
|
||||
withFixes : Bool -> Maybe Int -> ReviewOptions -> ReviewOptions
|
||||
withFixes enableFixes limit (ReviewOptionsInternal reviewOptions) =
|
||||
let
|
||||
fixes : Internal.Fixes
|
||||
fixes =
|
||||
if enableFixes then
|
||||
Internal.Enabled limit
|
||||
withFixes : FixMode -> ReviewOptions -> ReviewOptions
|
||||
withFixes fixMode (ReviewOptionsInternal reviewOptions) =
|
||||
ReviewOptionsInternal { reviewOptions | fixMode = fixMode }
|
||||
|
||||
else
|
||||
Internal.Disabled
|
||||
in
|
||||
ReviewOptionsInternal { reviewOptions | fixes = fixes }
|
||||
|
||||
type alias FixMode =
|
||||
Internal.FixMode
|
||||
|
||||
|
||||
fixesEnabledWithoutLimits : Internal.FixMode
|
||||
fixesEnabledWithoutLimits =
|
||||
Internal.Enabled Nothing
|
||||
|
||||
|
||||
fixesEnabledWithLimit : Int -> Internal.FixMode
|
||||
fixesEnabledWithLimit limit =
|
||||
Internal.Enabled (Just limit)
|
||||
|
||||
|
||||
fixedDisabled : Internal.FixMode
|
||||
fixedDisabled =
|
||||
Internal.Disabled
|
||||
|
||||
|
||||
{-| Add suppressions from the suppressed folder.
|
||||
|
@ -1,6 +1,7 @@
|
||||
module Review.Options.Internal exposing (Fixes(..), ReviewOptionsData, ReviewOptionsInternal(..), shouldFindFix)
|
||||
module Review.Options.Internal exposing (FixMode(..), ReviewOptionsData, ReviewOptionsInternal(..), shouldAbort, shouldFindFix)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Review.Fix.FixedErrors as FixedErrors exposing (FixedErrors)
|
||||
import Review.Logger exposing (Logger)
|
||||
|
||||
|
||||
@ -11,20 +12,19 @@ type ReviewOptionsInternal
|
||||
type alias ReviewOptionsData =
|
||||
{ extract : Bool
|
||||
, logger : Logger
|
||||
, fixes : Fixes
|
||||
, fixLimit : Maybe Int
|
||||
, fixMode : FixMode
|
||||
, suppressions : Dict ( String, String ) Int
|
||||
}
|
||||
|
||||
|
||||
type Fixes
|
||||
type FixMode
|
||||
= Disabled
|
||||
| Enabled (Maybe Int)
|
||||
|
||||
|
||||
shouldFindFix : String -> ReviewOptionsData -> Maybe (String -> Bool)
|
||||
shouldFindFix ruleName reviewOptionsData =
|
||||
case reviewOptionsData.fixes of
|
||||
case reviewOptionsData.fixMode of
|
||||
Enabled _ ->
|
||||
if Dict.isEmpty reviewOptionsData.suppressions then
|
||||
Just (always True)
|
||||
@ -34,3 +34,16 @@ shouldFindFix ruleName reviewOptionsData =
|
||||
|
||||
Disabled ->
|
||||
Nothing
|
||||
|
||||
|
||||
shouldAbort : ReviewOptionsData -> FixedErrors -> Bool
|
||||
shouldAbort reviewOptionsData fixedErrors =
|
||||
case reviewOptionsData.fixMode of
|
||||
Enabled (Just fixLimit) ->
|
||||
fixLimit <= FixedErrors.count fixedErrors
|
||||
|
||||
Enabled Nothing ->
|
||||
False
|
||||
|
||||
Disabled ->
|
||||
False
|
||||
|
@ -310,7 +310,7 @@ import Review.ModuleNameLookupTable exposing (ModuleNameLookupTable)
|
||||
import Review.ModuleNameLookupTable.Compute
|
||||
import Review.ModuleNameLookupTable.Internal as ModuleNameLookupTableInternal
|
||||
import Review.Options as ReviewOptions exposing (ReviewOptions)
|
||||
import Review.Options.Internal exposing (ReviewOptionsData, ReviewOptionsInternal(..))
|
||||
import Review.Options.Internal as InternalOptions exposing (ReviewOptionsData, ReviewOptionsInternal(..))
|
||||
import Review.Project exposing (ProjectModule)
|
||||
import Review.Project.Dependency
|
||||
import Review.Project.Internal exposing (Project)
|
||||
@ -762,7 +762,7 @@ runRulesHelp reviewOptions remainingRules acc =
|
||||
errors =
|
||||
ListExtra.orderIndependentMapAppend errorToReviewError result.errors acc.errors
|
||||
in
|
||||
if shouldAbort reviewOptions result.fixedErrors then
|
||||
if InternalOptions.shouldAbort reviewOptions result.fixedErrors then
|
||||
{ errors = errors
|
||||
, fixedErrors = result.fixedErrors
|
||||
, rules = restOfRules ++ (result.rule :: acc.rules)
|
||||
@ -4400,7 +4400,7 @@ computeElmJson ({ reviewOptions, projectVisitor, exceptions } as dataToComputePr
|
||||
newFixedErrors =
|
||||
FixedErrors.insert fixResult.error fixedErrors
|
||||
in
|
||||
if shouldAbort reviewOptions newFixedErrors then
|
||||
if InternalOptions.shouldAbort reviewOptions newFixedErrors then
|
||||
{ project = fixResult.project, step = Abort, cache = cache, fixedErrors = newFixedErrors }
|
||||
|
||||
else
|
||||
@ -4421,16 +4421,6 @@ computeElmJson ({ reviewOptions, projectVisitor, exceptions } as dataToComputePr
|
||||
{ project = project, step = Readme { initial = inputContext, elmJson = outputContext }, cache = { cache | elmJson = Just elmJsonEntry }, fixedErrors = fixedErrors }
|
||||
|
||||
|
||||
shouldAbort : ReviewOptionsData -> FixedErrors -> Bool
|
||||
shouldAbort reviewOptionsData fixedErrors =
|
||||
case reviewOptionsData.fixLimit of
|
||||
Just fixLimit ->
|
||||
fixLimit <= FixedErrors.count fixedErrors
|
||||
|
||||
Nothing ->
|
||||
False
|
||||
|
||||
|
||||
computeReadme :
|
||||
DataToComputeProject projectContext moduleContext
|
||||
-> ValidProject
|
||||
@ -4507,7 +4497,7 @@ computeReadme ({ reviewOptions, projectVisitor, exceptions } as dataToComputePro
|
||||
newFixedErrors =
|
||||
FixedErrors.insert fixResult.error fixedErrors
|
||||
in
|
||||
if shouldAbort reviewOptions newFixedErrors then
|
||||
if InternalOptions.shouldAbort reviewOptions newFixedErrors then
|
||||
{ project = fixResult.project, step = Abort, cache = cache, fixedErrors = newFixedErrors }
|
||||
|
||||
else
|
||||
@ -4608,7 +4598,7 @@ computeDependencies { reviewOptions, projectVisitor, exceptions } project contex
|
||||
newFixedErrors =
|
||||
FixedErrors.insert fixResult.error fixedErrors
|
||||
in
|
||||
if shouldAbort reviewOptions newFixedErrors then
|
||||
if InternalOptions.shouldAbort reviewOptions newFixedErrors then
|
||||
{ project = fixResult.project, step = Abort, cache = cache, fixedErrors = newFixedErrors }
|
||||
|
||||
else
|
||||
@ -4691,7 +4681,7 @@ computeFinalProjectEvaluation { reviewOptions, projectVisitor, exceptions } proj
|
||||
-- Unnecessary to cache the final evaluation errors, since we'll end up with a different project context next time
|
||||
, cache = cache
|
||||
, step =
|
||||
if shouldAbort reviewOptions newFixedErrors then
|
||||
if InternalOptions.shouldAbort reviewOptions newFixedErrors then
|
||||
Abort
|
||||
|
||||
else
|
||||
@ -4841,7 +4831,7 @@ computeModule dataToComputeModules module_ projectContext project moduleZipper f
|
||||
newFixedErrors =
|
||||
FixedErrors.insert fixResult.error fixedErrors
|
||||
in
|
||||
if shouldAbort dataToComputeModules.reviewOptions newFixedErrors then
|
||||
if InternalOptions.shouldAbort dataToComputeModules.reviewOptions newFixedErrors then
|
||||
{ project = fixResult.project
|
||||
, analysis = analysis ()
|
||||
, nextStep = NextStepAbort
|
||||
@ -5082,7 +5072,7 @@ type FixedFile
|
||||
|
||||
findFix : ReviewOptionsData -> String -> ValidProject -> List (Error a) -> Maybe (Zipper (Graph.NodeContext ModuleName ())) -> Maybe { project : ValidProject, fixedFile : FixedFile, error : ReviewError }
|
||||
findFix reviewOptions ruleName_ project errors maybeModuleZipper =
|
||||
case Review.Options.Internal.shouldFindFix ruleName_ reviewOptions of
|
||||
case InternalOptions.shouldFindFix ruleName_ reviewOptions of
|
||||
Just fixablePredicate ->
|
||||
findFixHelp project fixablePredicate errors maybeModuleZipper
|
||||
|
||||
|
@ -26,7 +26,7 @@ b = 1
|
||||
"""
|
||||
}
|
||||
in
|
||||
Rule.reviewV3 (Review.Options.defaults |> Review.Options.withFixes False)
|
||||
Rule.reviewV3 (Review.Options.defaults |> Review.Options.withFixes Review.Options.fixedDisabled)
|
||||
[ NoUnused.Variables.rule ]
|
||||
project
|
||||
|> .project
|
||||
@ -47,7 +47,7 @@ b = 1
|
||||
"""
|
||||
}
|
||||
in
|
||||
Rule.reviewV3 (Review.Options.defaults |> Review.Options.withFixes True)
|
||||
Rule.reviewV3 (Review.Options.defaults |> Review.Options.withFixes Review.Options.fixesEnabledWithoutLimits)
|
||||
[ NoUnused.Variables.rule ]
|
||||
project
|
||||
|> .project
|
||||
|
Loading…
Reference in New Issue
Block a user