matzko/elm-review-limit-aliased-record-size/1.0.0

NOTE: the latest version is 1.0.3

LimitAliasedRecordSize

Configuration

LimitRecordSizeConfig gets passed to rule to configure the rule. You can't contruct this type directly, but you can use the maxRecordSize function to create a configuration value:

import LimitAliasedRecordSize
import Review.Rule exposing (Rule)


config : List Rule
config =
    [ LimitAliasedRecordSize.rule
        (20 |> LimitAliasedRecordSize.maxRecordSize)
    ]

Assign the max record size allowed when configuring this rule.

import LimitAliasedRecordSize
import Review.Rule exposing (Rule)


config : List Rule
config =
    [ LimitAliasedRecordSize.rule
        (20 |> LimitAliasedRecordSize.maxRecordSize)
    ]

LimitAliasedRecordSize Rule Usage

Configure the rule in your elm-review configuration:

import LimitAliasedRecordSize
import Review.Rule exposing (Rule)


config : List Rule
config =
    [ LimitAliasedRecordSize.rule
        (20 |> LimitAliasedRecordSize.maxRecordSize)
    ]

Examples

✅ Good: not too many fields

type alias MyRecord =
    { oneField : Int
    , anotherField : String
    , yetAnotherField : Bool
    }

❌ Bad: too many fields

type alias MyRecord =
    { oneField : Int
    , anotherField : String
    , yetAnotherField : Bool
    , andAnotherField : Int
    , andAnotherField2 : Int
    , andAnotherField3 : Int
    , andAnotherField4 : Int
    , andAnotherField5 : Int
    , andAnotherField6 : Int
    , andAnotherField7 : Int
    , andAnotherField8 : Int
    , andAnotherField9 : Int
    , andAnotherField10 : Int
    , andAnotherField11 : Int
    , andAnotherField12 : Int
    , andAnotherField13 : Int
    }

How to fix

One simple approach is just to change the record into a custom type. For example, the above bad example can be changed to:

type MyRecord
    = MyRecord
        { oneField : Int
        , anotherField : String
        , yetAnotherField : Bool
        , andAnotherField : Int
        , andAnotherField2 : Int
        , andAnotherField3 : Int
        , andAnotherField4 : Int
        , andAnotherField5 : Int
        , andAnotherField6 : Int
        , andAnotherField7 : Int
        , andAnotherField8 : Int
        , andAnotherField9 : Int
        , andAnotherField10 : Int
        , andAnotherField11 : Int
        , andAnotherField12 : Int
        , andAnotherField13 : Int
        }

Try it out

You can try the example configuration above out by running the following command:

elm-review --template matzko/elm-review-limit-aliased-record-size/example