jxxcarlson/elm-review-codeinstaller/6.0.1

NOTE: the latest version is 13.0.0

Install.ClauseInCase

Add a clause to a case expression in a specified function in a specified module. For example, if you put the code below in your ReviewConfig.elm file, running elm-review --fix will add the clause ResetCounter to the updateFromFrontend function in the Backend module.

-- code for ReviewConfig.elm:
Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
    |> Install.ClauseInCase.makeRule


Thus we will have


updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
    case msg of
        CounterIncremented ->
        ...
        CounterDecremented ->
        ...
        ResetCounter ->
            ( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )


You also can add the clause after another clause of choice with the `withInsertAfter` function:
    Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
        |> Install.ClauseInCase.withInsertAfter "CounterIncremented"
        |> Install.ClauseInCase.makeRule


In this case we will have
    updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
    updateFromFrontend sessionId clientId msg model =
        case msg of
            CounterIncremented ->
            ...
            ResetCounter ->
                ( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )


            CounterDecremented ->
            ...
You can also customize the error message with the `withCustomErrorMessage` function:
    Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
        |> Install.ClauseInCase.withCustomErrorMessage "Add handler for ResetCounter" []
        |> Install.ClauseInCase.makeRule
init : String -> String -> String -> String -> Config

Basic config to add a new clause to a case expression. If you just need to add a new clause at the end of the case, you can simply use it with the makeRule function like this:

Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
    |> Install.ClauseInCase.makeRule
If you need additional configuration, check the `withInsertAfter` and `withCustomErrorMessage` functions.
makeRule : Config -> Rule

Create a makeRule that adds a clause to a case expression in a specified function. You can use it like this:

Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
    |> Install.ClauseInCase.makeRule

Add a clause after another clause of choice in a case expression. If the clause to insert after is not found, the new clause will be inserted at the end.

Example

Given the following module:

module Philosopher exposing (Philosopher(..), stringToPhilosopher)


type Philosopher
    = Socrates
    | Plato
    | Aristotle


stringToPhilosopher : String -> Maybe Philosopher
stringToPhilosopher str =
    case str of
        "Socrates" ->
            Just Socrates


        "Plato" ->
            Just Plato


        "Aristotle" ->
            Just Aristotle


        _ ->
            Nothing

To add the clause Aspasia after the clause Aristotle, you can use the following configuration:

Install.ClauseInCase.init "Philosopher" "stringToPhilosopher" "Aspasia" "Just Aspasia"
    |> Install.ClauseInCase.withInsertAfter "Aristotle"
    |> Install.ClauseInCase.makeRule

This will add the clause Aspasia after the clause Aristotle in the stringToPhilosopher function, resulting in:

stringToPhilosopher : String -> Maybe Philosopher
stringToPhilosopher str =
    case str of
        "Socrates" ->
            Just Socrates


        "Plato" ->
            Just Plato


        "Aristotle" ->
            Just Aristotle


        "Aspasia" ->
            Just Aspasia


        _ ->
            Nothing

Add a clause at the beginning of the case expression.

withCustomErrorMessage : String -> List String -> Config -> Config

Customize the error message that will be displayed when running elm-review --fix or elm-review --fix-all

type Config

Configuration for makeRule: add a clause to a case expression in a specified function in a specified module.

Custom error message to be displayed when running elm-review --fix or elm-review --fix-all