Skip to content

prefer_explicit_parameter_names

v1.0.0WarningConfigurableType Annotations

This rule flags a function type — in a typedef or a function-typed parameter — that declares unnamed parameters.

void Function(String, int) tells a reader the types and nothing else. At the point where someone writes the callback, (String, int) gives them two anonymous values to guess at — is the int an index, a count, an id? void Function(String label, int count) answers that in the signature, where the answer belongs, and IDEs echo those names into the closure they generate.

This rule is in the pedantic preset, and pedantic supplies min_parameters: 1 — so under that preset a single-parameter function type is reported too. The rule’s own default when you enable it by name is 2.

A callback whose parameters are anonymous, in a typedef and at a call boundary:

typedef OnChanged = void Function(String, int);
void listen(void Function(String, int) callback) {}

The reader writing listen((a, b) { ... }) has nothing to go on.

typedef OnChanged = void Function(String label, int count);
void listen(void Function(String label, int count) callback) {}

Naming one and not the other is still reported — the rule fires when any parameter is unnamed:

// Don't — `int` is still anonymous
typedef OnChanged = void Function(String label, int);
// Do
typedef OnChanged = void Function(String label, int count);

Single-parameter types under preset: pedantic

Section titled “Single-parameter types under preset: pedantic”

pedantic sets min_parameters: 1, so this is reported:

many_lints.yaml
rules:
prefer_explicit_parameter_names:
min_parameters: 1
// Don't
typedef OnTap = void Function(String);
// Do
typedef OnTap = void Function(String routeName);

Set min_parameters: 2 to get the rule’s own default back — void Function(T) is unambiguous from the type alone:

many_lints.yaml
rules:
prefer_explicit_parameter_names:
min_parameters: 2
// Not reported at `min_parameters: 2`
typedef OnTap = void Function(String);

See also: Effective Dart: type annotations

analysis_options.yaml
many_lints:
rules:
prefer_explicit_parameter_names:
min_parameters: 2
Option Type Default Description
min_parameters int 2 Fewest parameters a function type must have before names are required. preset: pedantic overrides this to 1

To disable this rule:

many_lints.yaml
rules:
prefer_explicit_parameter_names: false

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