Skip to content

prefer_correct_setter_parameter_name

v1.0.0WarningConfigurableClass Naming

This rule flags a setter whose parameter does not use the configured name.

A setter has exactly one parameter and its name appears nowhere but the body, so the only thing it communicates is which convention the file follows. When half the setters say value and half say newValue or v, a reader scanning a class of setters has to look at each one to be sure nothing else is going on.

An override is skipped, since it inherits its parameter name along with the signature.

This rule is in the pedantic preset.

class TableColumn {
int _width = 0;
set width(int newValue) => _width = newValue;
}
class TableColumn {
int _width = 0;
set width(int value) => _width = value;
}

A setter marked @override inherits its parameter name along with the signature, so renaming it would only diverge from the base:

class Base {
set width(int value) {}
}
class TableColumn extends Base {
// Not reported — the name comes with the inherited signature
@override
set width(int newValue) {}
}

allow_names adds spellings alongside the default, for the setters where value genuinely reads worse:

rules:
prefer_correct_setter_parameter_name:
allow_names: [newValue]
class TableColumn {
int _width = 0;
// Both accepted with the config above
set width(int value) => _width = value;
set minWidth(int newValue) => _width = newValue;
// Still reported — `v` is in neither
set maxWidth(int v) => _width = v;
}

Set parameter_name when the house word is the only one you want:

rules:
prefer_correct_setter_parameter_name:
parameter_name: newValue
class TableColumn {
int _width = 0;
// Don't — `value` is no longer the accepted name
set width(int value) => _width = value;
// Do
set height(int newValue) => _width = newValue;
}

Setters only. A single-parameter method that acts as a setter (void setWidth(int w)) is not checked.

No quick fix. The parameter name appears in the body as well as the signature, and renaming both is a rename refactoring rather than a one-token edit.

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
prefer_correct_setter_parameter_name:
enabled: true
analysis_options.yaml
many_lints:
rules:
prefer_correct_setter_parameter_name:
parameter_name: value
allow_names: []
Option Type Default Description
parameter_name string value The name every setter parameter should use
allow_names list [] Additional spellings accepted alongside the default

To disable this rule:

many_lints.yaml
rules:
prefer_correct_setter_parameter_name: false

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