parameters_ordering
This rule flags a function whose named parameters are not in the configured order.
A long named-parameter list has the same problem as a long map literal: without an order, checking whether a parameter already exists means reading all of them, and a new one gets appended at the end beside the near-duplicate nobody saw.
Positional parameters are never ordered. They are ordered by meaning and by every call site that depends on them — sorting those would break the code.
Outside preset: pedantic, this rule reports nothing until configured, since a widget constructor deliberately leads with its most important parameters. The pedantic preset chooses alphabetical order, sorts required and optional parameters independently, and checks lists from two named parameters upward.
By default required and optional parameters are sorted as independent groups.
Their relative placement is deliberately left to the official Dart rule
always_put_required_named_parameters_first,
so the two rules do not report the same issue.
This rule is in the pedantic preset.
void configure({ required String name, required String id, String? theme, int? timeout, bool? verbose,})void configure({ required String id, required String name, String? theme, int? timeout, bool? verbose,})Enabling this rule
Section titled “Enabling this rule”Outside preset: pedantic, enabling it by name is not enough — set order::
rules: parameters_ordering: order: alphabeticalOptions
Section titled “Options”many_lints: rules: parameters_ordering: order: alphabetical group_required: true min_parameters: 5rules: parameters_ordering: order: alphabetical group_required: true min_parameters: 5| Option | Type | Default | Description |
|---|---|---|---|
order |
string | — |
alphabetical, alphabetical_case_sensitive or by_length. Unset means the rule is silent |
group_required |
bool | true |
Sort required and optional parameters as separate groups |
min_parameters |
int | 5 |
How many named parameters a signature needs before order is checked |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: parameters_ordering: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”arguments_ordering— Keep named arguments in a configured order.initializers_ordering— Keep constructor initializers in field order.map_keys_ordering— Keep map literal keys in a configured order.member_ordering— Keep class members in a configured order.