Skip to main content

match-base-class-default-value

effort: 2m
has IDE fix
teams+

Warns when the default value of a parameter in an overridden method does not match the default value of the base class parameter.

Changing the default value of a parameter can lead to subtle bugs when some subclasses of the base class have different behavior due to different default values.

Additionally, this rule helps spot changes in the base class default values that have not been propagated to subclasses.

Example

❌ Bad:

class A {
void work({bool defaultValue = false}) {
...
}
}

class B implements A {
// LINT: This default value does not match the default value of the base class parameter.
// Try changing it to match the base class default value.

void work({bool defaultValue = true}) {
...
}
}

✅ Good:

class A {
void work({bool defaultValue = false}) {
...
}
}

class B implements A {

void work({bool defaultValue = false}) {
...
}
}