Skip to main content

prefer-named-boolean-parameters

added in: 1.8.0
⚙️
Pro+

Warns when a declaration has a boolean positional parameter.

Converting positional boolean parameters to named parameters helps you avoid situations with a wrong value passed to the parameter.

This rule is an improved version of https://dart.dev/tools/linter-rules/avoid_positional_boolean_parameters.

⚙️ Config

Set ignore-single (default is false) to ignore declarations that have only one parameter.

Set ignore-single-boolean (default is false) to ignore declarations that have only one boolean parameter.

dart_code_metrics:
...
rules:
...
- prefer-named-boolean-parameters:
ignore-single: true
ignore-single-boolean: true

Example

❌ Bad:

// LINT
void someFunction(String name, bool isExternal, bool isTemporary) {
...
}

someFunction('User', true, false);

✅ Good:

void someFunction(
String name, {
required bool isExternal,
required bool isTemporary,
}) {
...
}

someFunction('User', isExternal: true, isTemporary: false);