A package designed to make it easy to add pieces of code to an existing codebase using elm-review rules. This package provides a set of tools to help you automatically insert clauses in case expressions, fields in type aliases, fields in initializer functions, and variants in custom types.
The project is still in development, so expect it to change a lot over the next weeks and likely months. For now, consider it to be an experiment.
To install elm-review-codeinstaller, add it to your elm.json dependencies:
elm install jxxcarlson/elm-review-codeinstallerSuppose you have the following Msg type and update function in your Counter module:
module Counter exposing (..)
type Msg
= Increment
| Decrement
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Increment ->
( { model | counter = model.counter + 1 }, Cmd.none)
Decrement ->
( { model | counter = model.counter - 1 }, Cmd.none)To add a new ResetCounter variant to the Msg type and handle it in the update function, your ReviewConfig.elm file would look like the following:
module ReviewConfig exposing (config)
import Install.ClauseInCase
import Install.TypeVariant
import Review.Rule exposing (Rule)
config : List Rule
config =
addResetCounter ++
[ -- other rules
]
addResetCounter : List Rule
addResetCounter =
[ addResetCounterVariant
, addResetCounterClause
]
addResetCounterVariant : Rule
addResetCounterVariant =
Install.TypeVariant.makeRule "Counter" "Msg" "ResetCounter"
addResetCounterClause : Rule
addResetCounterClause =
Install.ClauseInCase.init "Counter" "update" "ResetCounter" "( { model | counter = 0 }, Cmd.none )"
|> Install.ClauseInCase.makeRuleAfter running elm-review --fix, your Counter module will be updated as follows:
module Counter exposing (..)
type Msg
= Increment
| Decrement
| ResetCounter
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Increment ->
( { model | counter = model.counter + 1 }, Cmd.none )
Decrement ->
( { model | counter = model.counter - 1 }, Cmd.none )
ResetCounter ->
( { model | counter = 0 }, Cmd.none )elm-review-codeinstaller includes the following modules:
( Model, Cmd msg ). For more details, see the docs.To test the review code in its current state, try running this in a clean Lamdera project:
npx elm-review --template jxxcarlson/elm-review-codeinstaller/exampleContributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.
James Carlson and Mateus Leite.
This package is licensed under the MIT License.