Boolean parameter is positional rather than named
ID |
dart.maintainability.avoid_positional_boolean |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Api Design |
Language |
Dart |
Description
Reports a function or method that takes a bool (or bool?) as a positional parameter. Booleans declared inside a named parameter group are not reported.
Rationale
A positional boolean carries no meaning at the call site. render(label, true) says nothing about what true selects, so the reader has to open the declaration to find out, and two adjacent boolean parameters can be swapped without the compiler noticing - the call still type-checks and quietly does the wrong thing. Dart has named parameters precisely so the argument can name the choice it makes, and the cost of not using them grows with the lifetime of the API, since adding a second flag later turns every existing call into a puzzle.
The following code illustrates the pattern detected by this rule:
class Report {
// FLAGGED: Boolean parameter is positional rather than named
void setEnabled(bool enabled) {
print(enabled);
}
}