Provides elm-review rules for opinionated simplification of Elm code.
This package was generated with Claude Code. There may be bugs -- pull requests are welcome.
PreferMaybeChaining - Reports case expressions on Maybe that can be simplified using Maybe.map, Maybe.andThen, Maybe.withDefault, or Maybe.Extra.withDefaultLazy.SimplifyLambdaToComposition - Reports lambdas like (\x -> func x.field) that can be simplified to function composition (func << .field).module ReviewConfig exposing (config)
import PreferMaybeChaining
import Review.Rule exposing (Rule)
import SimplifyLambdaToComposition
config : List Rule
config =
[ PreferMaybeChaining.rule
, SimplifyLambdaToComposition.rule
]Note: This rule suggests using Maybe.Extra.withDefaultLazy for complex default expressions. Make sure elm-community/maybe-extra is installed in your project.
-- Before
case maybeValue of
Nothing -> Nothing
Just x -> Just (f x)
-- After
maybeValue
|> Maybe.map (\x -> f x)-- Before
case maybeId of
Nothing -> Nothing
Just id -> Store.findById id store
-- After
maybeId
|> Maybe.andThen (\id -> Store.findById id store)Pipe chains are flattened:
-- Before
case maybeId of
Nothing -> Nothing
Just id -> lookup id |> Maybe.map .name
-- After
maybeId
|> Maybe.andThen (\id -> lookup id)
|> Maybe.map .name-- Before
case maybeValue of
Nothing -> 0
Just x -> x
-- After
maybeValue
|> Maybe.withDefault 0Used when the default expression is not a simple literal or variable:
-- Before
case maybeValue of
Nothing -> computeDefault model
Just x -> x
-- After
maybeValue
|> Maybe.Extra.withDefaultLazy (\() -> computeDefault model)-- Before
List.sortBy (\todo -> Time.posixToMillis todo.createdAt) todos
-- After
List.sortBy (Time.posixToMillis << .createdAt) todosNested function applications are also handled:
-- Before
List.map (\x -> f (g x.field)) list
-- After
List.map (f << g << .field) listYou can try the example configuration above out by running the following command:
elm-review --template alex-tan/elm-review-opinionated-simplify/example