Skip to main content

parameters-ordering

added in: 1.9.0
⚙️🛠

Ensures consistent alphabetical order of parameters by their names.

warning

When applying quick fixes for this rule, the arguments passed to invocations do not get updated automatically.

⚙️ Config

Set default (default is unset, can be set to first, last or unset) to configure ordering rules for parameters with default values.

Set super (default is unset, can be set to first, last or unset) to configure ordering rules for super parameters.

Set required (default is unset, can be set to first, last or unset) to configure ordering rules for required parameters.

Set ignore-overridden (default is false) to exclude overridden methods.

dart_code_metrics:
...
rules:
...
- parameters-ordering:
required: 'first'
default: 'last'

Example

❌ Bad:

void named({String b, String a}) {} // LINT

void optional([String? b, String? a]) {} // LINT

void mixed(String b, String a, {int c}) {} // LINT

void anotherMixed(String a, String b, [int d, int c]) {} // LINT

✅ Good:

void namedCorrect({String a, String b}) {}

void optionalCorrect([String? a, String? b]) {}

void mixedCorrect(String a, String b, {int c}) {}

void mixedAnotherCorrect(String a, String d, {int c}) {}