prefer_named_parameters
v1.0.0WarningConfigurableCode Quality
analysis_options.yaml many_lints.yaml
many_lints.yaml
This rule flags a declaration taking more than a few positional parameters.
This rule is in the pedantic preset: the budget is a house style.
Why use this rule
Section titled “Why use this rule”move(3, 4, 5) tells the reader nothing, and swapping two arguments of the same type compiles cleanly and fails at runtime. Named parameters put the meaning at the call site, where it is read.
The threshold matters more than the principle. One or two positional parameters are usually the subject of the call — substring(0, 4), Point(x, y) — and naming them is noise, so the default budget is 2.
Exempt by default:
- An
@override, whose signature belongs to the supertype, and an operator, whose parameters cannot be named. - A private constructor. It is not an API: it is reached from one place in the same library, usually a factory assembling injected dependencies (
Pipeline._(this._storage, this._adapter, this._policy)), and naming those adds ceremony at the one call site that already knows the order. main,onRequestandmiddleware, whose positional signature a framework dictates. dart_frog passes the URL’s path segments in order, so naming them is not the author’s to decide.
Those last two accounted for 22 of 28 reports on a real codebase.
See also: Effective Dart: parameters
void move(int x, int y, int z) {}void move({required int x, required int y, required int z}) {}
// One or two positional parameters are the subject of the call.String slice(String value, int start) => value;Options
Section titled “Options”many_lints: rules: prefer_named_parameters: max_positional: 2 additional_ignored_names: [handleRequest] ignore_private_constructors: truerules: prefer_named_parameters: max_positional: 2 additional_ignored_names: [handleRequest] ignore_private_constructors: true| Option | Type | Default | Description |
|---|---|---|---|
max_positional |
int | 2 |
Most positional parameters a declaration may take |
ignored_names |
list of strings | [main, onRequest, middleware] |
Declarations whose signature a framework dictates |
additional_ignored_names |
list of strings | [] |
Names to add to that list |
ignore_private_constructors |
bool | true |
Skip Type._(...), which is not an API |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_named_parameters: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_private_named_parameters— Prefer private named parameters (Dart 3.12+) over initializer-list boilerplate.avoid_accessing_other_classes_private_members— Make the underscore mean what everyone reads it as.avoid_commented_out_code— Detect and flag commented-out code.avoid_complex_conditions— Keep boolean conditions within an operand budget.