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 (example).

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

analysis_options.yaml
dart_code_metrics:
rules:
- prefer-named-boolean-parameters:
ignore-single: false
ignore-single-boolean: false

Example

❌ Bad:

// LINT: Prefer named boolean parameters. Try converting this parameter to a named parameter.
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);

Example with "ignore-single"

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

✅ Good:

// Correct, ignored
void someFunction(bool isExternal) {
...
}

Example with "ignore-single-boolean"

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

✅ Good:

// Correct, ignored
void someFunction(String name, bool isExternal) {
...
}