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.

This rule is in the pedantic preset.

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.

A single-parameter function type is exempt by default: void Function(T) is unambiguous from the type alone, and naming it adds nothing.

See also: Effective Dart: type annotations

typedef OnChanged = void Function(String, int);
void listen(void Function(String, int) callback) {}
typedef OnChanged = void Function(String label, int count);
void listen(void Function(String label, int count) callback) {}
// Exempt by default — unambiguous from the type alone.
typedef OnTap = void Function(String);
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

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.