Skip to content

prefer_boolean_prefixes

v1.0.0 Warning Class Naming

This rule flags a boolean field, getter or method whose name does not read as a yes-or-no question.

if (user.admin) reads as though admin might be an object, and the reader has to check. if (user.isAdmin) can only be a condition. The verb is what tells you at the call site that nothing further is needed to get a boolean out of it, and it is why isEmpty, hasListeners and canPop read the way they do throughout the SDK.

This rule is in the pedantic preset. Naming is where reasonable codebases disagree most, and the empirical run found a legitimate style it cannot accommodate: a predicate like screen.atLeast(Breakpoint.tablet) reads perfectly without a question verb. Enable it by name if the convention is one you want enforced.

See also: Effective Dart: naming

The verb does not have to lead. localeIsDefault asks the same question as isDefaultLocale, and naming the subject first is a normal way to keep related settings sorting together — so any of the recognised verbs appearing as a whole word satisfies the rule.

A bare third-person verb (involves, matches) is already a question and needs no prefix.

Three things are never reported: an @override, whose name belongs to the base declaration; a setter, whose name is fixed by the getter it pairs with; and a private field backing an accessor, which is named after the storage while the accessor carries the readable name.

class User {
bool admin = false;
bool emailSent = false;
}
class User {
bool isAdmin = false;
bool hasSentEmail = false;
}

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
prefer_boolean_prefixes:
enabled: true

To disable this rule:

many_lints.yaml
rules:
prefer_boolean_prefixes: false

To keep the rule on but skip certain paths, use per-rule exclude.