This module contains various PipelineFix
s that can be used to fix failing
pipelines. Pre-made rules already contain fixes were possible, so if you're only
using those, you shouldn't need this module.
Fixes may be specified with
ReviewPipelineStyles.andTryToFixThemBy
as follows. If, for example, one made the following rule to detect undesired
multi-step <|
pipelines:
forbid leftPizzaPipelines
|> that (haveMoreStepsThan 1)
|> andCallThem "<| pipeline with several steps"
then automatic fixes could be used to convert such pipelines to |>
pipelines as follows:
forbid leftPizzaPipelines
|> that (haveMoreStepsThan 1)
-- Adding fixes vvvv
|> andTryToFixThemBy convertingToRightPizza
-- Adding fixes ^^^^
|> andCallThem "<| pipeline with several steps"
Note that all fixes will only run if it is possible to fix the pipeline that way, i.e. that the fix will not generate invalid code. Look through Fixes for pre-made fixes or write your own using Custom Fixes.
eliminatingInputStep : PipelineFix ReviewPipelineStyles.Predicates.ApplicationPipeline
A fix that eliminates the input step of a pipeline by applying it directly to the next step, e.g.
a =
foo |> bar |> baz
becomes
a =
bar foo |> baz
Note that this fix will only be applied if the input step actually can be
combined in this way. It is thus recommended that you combine it with
ReviewPipelineStyles.Predicates.haveASimpleInputStep
or the like.
makingMultiline : PipelineFix pipelineType
Force a pipeline to span a new line with each step. This will not run on
pipelines that already span multiple lines. It is thus recommended that you
combine it with a negated
ReviewPipelineStyles.Predicates.spanMultipleLines
or the like.
This fix (as with most) relies on elm-format
to clean up the resulting code.
makingSingleLine : PipelineFix pipelineType
Force a pipeline onto a single line. This can only run on a very limited
set of pipelines, due to the possibility of generating invalid code.
Specifically, for this fix to run, all steps of a pipeline must consist of
expressions on a single line and no comments may exist in the pipeline (as they
would get clobbered by the fix). It will, of course, also not run on a pipeline
that is already on a single line, so it is recommended that you combine it with
ReviewPipelineStyles.Predicates.spanMultipleLines
or the like.
convertingToRightPizza : PipelineFix ReviewPipelineStyles.Predicates.ApplicationPipeline
Convert an application pipeline to right function application (|>
). This
requires there to be no internal comments (as they would be clobbered), to not
already be a right function application pipeline, and to not be an immediate
nested pipeline (as operator precedence rules preclude this).
convertingToLeftPizza : PipelineFix ReviewPipelineStyles.Predicates.ApplicationPipeline
Convert an application pipeline to left function application (<|
). This
requires there to be no internal comments (as they would be clobbered), to not
already be a left function application pipeline, and to not be an immediate
nested pipeline (as operator precedence rules preclude this).
convertingToParentheticalApplication : PipelineFix ReviewPipelineStyles.Predicates.ApplicationPipeline
Convert an application pipeline to parenthetical function application. This requires there to be no internal comments (as they would be clobbered) and to not already be a parenthetical function application pipeline.
convertingToRightComposition : PipelineFix ReviewPipelineStyles.Predicates.CompositionPipeline
Convert a composition pipeline to right function composition (>>
). This
requires there to be no internal comments (as they would be clobbered), to not
already be a right function composition pipeline, and to not be an immediate
nested pipeline (as operator precedence rules preclude this).
convertingToLeftComposition : PipelineFix ReviewPipelineStyles.Predicates.CompositionPipeline
Convert a composition pipeline to left function composition (<<
). This
requires there to be no internal comments (as they would be clobbered), to not
already be a left function composition pipeline, and to not be an immediate
nested pipeline (as operator precedence rules preclude this).
If you need fixes beyond what is provided above, you can create them manually
by writing a function of type
(Range -> String) -> Pipeline -> Maybe (List Fix)
or
ModuleNameLookupTable -> (Range -> String) -> Pipeline -> Maybe (List Fix)
and
using one of the functions below.
Use the functions in Getting Information About Pipelines to build your custom fix.
fix : ((Elm.Syntax.Range.Range -> String) -> ReviewPipelineStyles.Predicates.Pipeline -> Maybe (List Review.Fix.Fix)) -> PipelineFix pipelineType
Create a PipelineFix
from a function that takes a source code extractor
and a Pipeline
and maybe returns a list of fixes. Needless to say, this is
dangerous, as it is possible to generate invalid code if you are not careful.
If you think a generally useful fix is missing, please open an issue or PR on Github: https://github.com/SiriusStarr/elm-review-pipeline-styles/issues
fixWithLookupTable : (Review.ModuleNameLookupTable.ModuleNameLookupTable -> (Elm.Syntax.Range.Range -> String) -> ReviewPipelineStyles.Predicates.Pipeline -> Maybe (List Review.Fix.Fix)) -> PipelineFix pipelineType
Create a PipelineFix
from a function that takes a ModuleNameLookupTable
,
source code extractor, and a Pipeline
and maybe returns a list of fixes.
Needless to say, this is dangerous, as it is possible to generate invalid code
if you are not careful.
If you think a generally useful fix is missing, please open an issue or PR on Github: https://github.com/SiriusStarr/elm-review-pipeline-styles/issues
These are exposed only for the sake of type annotations; you shouldn't need to work with them directly.
Internal.Types.PipelineFix pipelineType
A means of fixing a pipeline, to (presumably) bring it stylistically inline with what is desired.