Provides an elm-review rule to limit the number of positional arguments to functions.
NoTooManyPositionalArguments - Reports functions that have too many positional arguments and can auto-fix them to use a record parameter instead.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.
When a function has too many positional arguments, the rule reports an error and provides an automatic fix that:
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"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" }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).
The auto-fix is intentionally suppressed when:
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.
You can try the example configuration above out by running the following command:
elm-review --template cekrem/elm-review-positional-arguments/example