Skip to main content

prefer-correct-setter-parameter-name

added in: 1.11.0
⚙️🛠
Pro+

Warns when the setter parameter name does not match the configured one.

⚙️ Config

Set ignored-names (default is empty) to ignore specific names (example).

Set allowed-names (default is [value]) to configure allowed names for the setter parameter.

analysis_options.yaml
dart_code_metrics:
rules:
- prefer-correct-setter-parameter-name:
allowed-names:
- newValue

Example

❌ Bad:

class Some {
String? _value;

// LINT: This name does not match any of the configured ones: newValue
set prop(String someValue) {
_value = someValue;
}
}

✅ Good:

class Some {
String? _value;

set prop(String newValue) {
_value = newValue;
}
}

Example with "ignored-names"

Config
analysis_options.yaml
dart_code_metrics:
rules:
- prefer-correct-setter-parameter-name:
ignored-names:
- val

✅ Good:

class Some {
String? _value;

set prop(String val) { // Correct, 'val' is ignored
_value = val;
}
}