lue-bird/elm-review-missing-record-field-lens/1.0.2

NOTE: the latest version is 2.1.0

elm-review-missing-record-field-lens

Often, I find myself writing code like this:

InputAdded path newInput ->
    { model
        | projects =
            model.projects
                |> ZipList.updateSelected
                    (\project ->
                        { project
                            | calls =
                                project.calls
                                    |> List.map
                                        (Tree.updateAt path
                                            (Tree.prependChild newInput)
                                        )
                        }
                    )
    }

which is ... suboptimal.

Using lenses:

import Field
import Accessors exposing (over)
import Accessors.Library exposing (onEach)

InputAdded path newInput ->
    model
        |> over
            ((Field.projects << ZipList.selected)
                << Field.calls
                << onEach
            )
            (Tree.updateAt path
                (Tree.prependChild newInput)
            )

the code becomes more readable.

The biggest pain-point with these lenses is the need to manually create one for every used field.

→ This elm-review rule generates all those record field lenses that don't exist yet.

In this example: Field.projects and Field.calls will automatically be generated in Field.elm.

lenses that work out of the box:

Note: It's also possible to generate custom lenses or to customize the generation of existing ones.

configuration

module ReviewConfig exposing (config)

import NoMissingRecordFieldLens
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoMissingRecordFieldLens.rule
        { generate = NoMissingRecordFieldLens.accessors
        , generateIn =
            ( "Accessors", [ "Library", "RecordFields" ] )
        }
    ]

See Config

suggestions?

→ contributing.