Skip to content

parameters_ordering

v1.0.0WarningConfigurableCode Organization

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,
})

Outside preset: pedantic, enabling it by name is not enough — set order::

many_lints.yaml
rules:
parameters_ordering:
order: alphabetical
analysis_options.yaml
many_lints:
rules:
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

To disable this rule:

many_lints.yaml
rules:
parameters_ordering: false

To keep the rule on but skip certain paths, use per-rule exclude.