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 auto-fix is intentionally suppressed when:
List.map (createUser "default").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