This module contains various PipelineFixs 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.
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.
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.
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).
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).
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.
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).
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.
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
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.
A means of fixing a pipeline, to (presumably) bring it stylistically inline with what is desired.
A fix that eliminates the input step of a pipeline by applying it directly to the next step, e.g.
becomes
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.haveASimpleInputStepor the like.