cekrem/elm-review-positional-arguments/1.0.0

NOTE: the latest version is 1.1.2

elm-review-positional-arguments

Provides an elm-review rule to limit the number of positional arguments to functions.

Provided rule

  • NoTooManyPositionalArguments - Reports functions that have too many positional arguments and can auto-fix them to use a record parameter instead.

Configuration

module ReviewConfig exposing (config)

import NoTooManyPositionalArguments
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoTooManyPositionalArguments.rule NoTooManyPositionalArguments.defaults
    ]

The default maximum is 4 positional arguments. Functions with 5 or more will be flagged.

What it does

When a function has too many positional arguments, the rule reports an error and provides an automatic fix that:

  1. Converts the function declaration to accept a single record with named fields
  2. Updates the type annotation (if present) to use a record type
  3. Updates all call sites within the same module to pass a record

Before

createUser : String -> String -> Int -> Bool -> String -> User
createUser name email age isAdmin role =
    { name = name, email = email, age = age, isAdmin = isAdmin, role = role }

register =
    createUser "Alice" "[email protected]" 30 False "admin"

After

createUser : { name : String, email : String, age : Int, isAdmin : Bool, role : String } -> User
createUser { name, email, age, isAdmin, role } =
    { name = name, email = email, age = age, isAdmin = isAdmin, role = role }

register =
    createUser { name = "Alice", email = "[email protected]", age = 30, isAdmin = False, role = "admin" }

When the fix is suppressed

The auto-fix is intentionally suppressed when:

  • Partial application is detected -- converting to a record would break curried usage like List.map (createUser "default").
  • Parameters use destructuring patterns -- e.g. foo (Just x) (Ok y) _ _ _ has no usable names for record fields.

In these cases, the error is still reported but must be fixed manually.

Try it out

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

elm-review --template cekrem/elm-review-positional-arguments/example