prefer_correct_setter_parameter_name
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;}Examples
Section titled “Examples”An override is skipped
Section titled “An override is skipped”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) {}}Accepting a second spelling
Section titled “Accepting a second spelling”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;}Changing the name outright
Section titled “Changing the name outright”Set parameter_name when the house word is the only one you want:
rules: prefer_correct_setter_parameter_name: parameter_name: newValueclass 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;}Known limitations
Section titled “Known limitations”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.
Enabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: prefer_correct_setter_parameter_name: enabled: trueOptions
Section titled “Options”many_lints: rules: prefer_correct_setter_parameter_name: parameter_name: value allow_names: []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 |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_correct_setter_parameter_name: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_correct_callback_field_name— Name callbacks onSomething, the way Flutter does.prefer_correct_error_name— Name exception and error classes with the matching suffix.prefer_correct_handler_name— Name event handlers after the event they answer.prefer_boolean_prefixes— Name booleans as questions.