prefer_boolean_prefixes
v1.0.0 Warning Class Naming
Flags a boolean field, getter, method or top-level function 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 — which is why isEmpty, hasListeners and canPop read the way they do throughout the SDK.
This rule is in the pedantic preset, and takes no configuration.
class User { bool admin = false; bool emailSent = false;
bool profileComplete() => true;}class User { bool isAdmin = false; bool hasSentEmail = false;
bool isProfileComplete() => true;}Examples
Section titled “Examples”The verb does not have to lead
Section titled “The verb does not have to lead”Any recognised verb counts as long as it appears as a whole camelCase word. Naming the subject first is a normal way to keep related settings sorting together:
class Settings { // All accepted bool isDefaultLocale = false; bool localeIsDefault = false; bool userCanEdit = false;}The recognised verbs are is are was were has have had can should will would does do did must needs allows contains supports enables requires wants shows hides accepts.
Word boundaries, not substrings
Section titled “Word boundaries, not substrings”Matching is on camelCase words, so a name that merely contains the letters is still reported:
// Don't — `island` is not `is`, and `hasty` is not `has`bool island = false; // LINTbool hasty = false; // LINT
// Dobool isIsland = false;bool isHasty = false;A bare third-person verb is already a question
Section titled “A bare third-person verb is already a question”A single lowercase word ending in s needs no prefix — it reads as a question on its own:
class Matcher { // Accepted bool matches() => true; bool involves() => true;}Only a single lowercase word qualifies, so emailSent is still reported.
Three declarations are never reported
Section titled “Three declarations are never reported”An @override takes its name from the base declaration, a setter from the getter it pairs with, and a private field backing an accessor from the storage rather than the question:
class Toggle { // Not reported — a private field beside an accessor bool _value = false;
bool get isEnabled => _value;
// Not reported — a setter's name is fixed by its getter set isEnabled(bool value) => _value = value;}
class AdminUser extends User { // Not reported — the name belongs to the base declaration @override bool admin = true;}Known limitations
Section titled “Known limitations”Only an explicit bool annotation. The type has to be written out. var isReady = false and a getter with an inferred return type are not checked.
No configuration. The verb list is fixed. If a legitimate house style does not fit it — a predicate like screen.atLeast(Breakpoint.tablet) reads perfectly without a question verb — silence it with // ignore: many_lints/prefer_boolean_prefixes or turn the rule off.
See also: Effective Dart: naming
Enabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: prefer_boolean_prefixes: enabled: trueTurning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_boolean_prefixes: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_correct_callback_field_name— Name callbacks onSomething, the way Flutter does.prefer_correct_error_name— Name exception and error classes with the matching suffix.prefer_correct_handler_name— Name event handlers after the event they answer.prefer_correct_setter_parameter_name— Use one parameter name in every setter.