Skip to main content

avoid-unnecessary-nullable-parameters

effort: 2m
has auto-fix
teams+

Warns when a private function or method has a nullable parameter that never gets a nullable value.

Such parameters can be made non-nullable which helps simplify the code.

note

This rule handles only private declarations. For public functions and methods use the check-parameters command.

Example

❌ Bad:

class Some {
void work() {
_fn('regular');
}

// LINT: Declared type is unnecessary marked as nullable. Try removing '?'.
void _fn(String? nullable) {
if (nullable == null) {
// handle nullable case
} else {
// handle regular case
}
}
}

✅ Good:

class Some {
void work() {
_fn('regular');
}

void _fn(String nullable) {
// handle regular case
}
}