# elm-review-positional-arguments

Provides an [`elm-review`](https://package.elm-lang.org/packages/jfmengels/elm-review/latest/) rule to limit the number of positional arguments to functions.

## Provided rule

- [`NoTooManyPositionalArguments`](https://package.elm-lang.org/packages/cekrem/elm-review-positional-arguments/1.0.0/NoTooManyPositionalArguments) - Reports functions that have too many positional arguments and can auto-fix them to use a record parameter instead.

## Configuration

```elm
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.

To customize the threshold:

```elm
config : List Rule
config =
    [ NoTooManyPositionalArguments.rule
        (NoTooManyPositionalArguments.withMaxArguments 3)
    ]
```

## 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

```elm
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" "alice@example.com" 30 False "admin"
```

### After

```elm
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 = "alice@example.com", age = 30, isAdmin = False, role = "admin" }
```

## Partial application awareness

The rule accounts for partial application (currying). If a function is partially applied somewhere in the module, the curried arguments are **not counted** toward the positional argument limit.

For example, if `createUser` has 5 parameters but is used as `List.map (createUser "default" "email" 30)`, only the remaining 2 arguments count as positional. Since 2 is within the default threshold of 4, no error is reported.

If the effective arity still exceeds the threshold, the error is reported but the auto-fix is suppressed (converting to a record would break curried usage).

## When the fix is suppressed

The auto-fix is intentionally suppressed when:

- **Partial application exists** -- the function is partially applied somewhere in the module, so converting to a record would break curried usage.
- **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:

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