boolean-prefixes
Same as boolean_prefixes in Pyramid Lint
- Group
- Style
- Path
lint/style/boolean-prefixes- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 194 of 512
Flags boolean identifiers that lack a conventional interrogative prefix.
A boolean named visible reads as a value, whereas isVisible reads as the
yes/no question it answers; a consistent prefix (is, has, can, ...)
makes conditions self-documenting. Only variables and fields initialized
with a boolean literal, and bool-returning methods, getters, and
functions, are checked — parameters and uninitialized fields are not. A
single leading underscore is stripped before matching, and @override
members are exempt because they cannot rename an inherited declaration.
Options
valid-prefixes (list of strings, default: ["is", "are", "was", "were", "has", "have", "had", "can", "should", "will", "do", "does", "did"]) —
accepted boolean-name prefixes. User-provided entries extend the defaults
rather than replacing them.
Invalid
// Violations: boolean-literal declarations and bool-returning members whose
// names lack a valid prefix.
class Flags {
bool active = true;
bool loading = false;
bool _enabled = true;
// A non-override method returning bool without a valid prefix.
bool getStatus() {
return true;
}
// A getter returning bool without a valid prefix.
bool get empty => !active;
void example() {
bool complete = false;
print(complete);
}
}
// A top-level function returning bool without a valid prefix.
bool validate() => true;
final callback = () {
final active = true;
};
void nestedDeclarations(int value) {
for (var ready = false; !ready; ready = true) {
print(ready);
}
switch (value) {
case 0:
final complete = false;
print(complete);
break;
}
label: {
final visible = true;
print(visible);
}
}
class Operand {
Operand operator +(Operand other) {
final enabled = true;
return other;
}
}class Flags { bool active = true; bool active = true; bool loading = false; bool loading = false; bool _enabled = true; // A non-override method returning bool without a valid prefix. bool getStatus() { // A getter returning bool without a valid prefix. bool get empty => !active; void example() { bool complete = false;// A top-level function returning bool without a valid prefix.bool validate() => true;final callback = () { final active = true;void nestedDeclarations(int value) { for (var ready = false; !ready; ready = true) { case 0: final complete = false; label: { final visible = true; Operand operator +(Operand other) { final enabled = true;Valid
// pyramid_lint only inspects variable/field declarations initialised with a
// boolean *literal*, and bool-returning methods/getters/functions. Parameters,
// uninitialised fields, and non-literal initialisers are all out of scope.
class Flags {
bool isActive = true;
bool hasPermission = false;
bool canEdit = true;
bool shouldRefresh = false;
bool _isDisposed = false; // leading underscore stripped -> isDisposed
// Uninitialised bool fields have no boolean literal, so they are not checked.
final bool active;
late bool loading;
// A non-literal initialiser (`!kDebugMode`) is out of scope.
bool enabled = !kDebugMode;
Flags(this.active);
// Parameters are never checked, even with a boolean-literal default.
void configure(bool ready, {bool fatal = false}) {
print(ready);
print(fatal);
bool isDone = true; // local with a valid prefix
print(isDone);
}
bool get isEmpty => !isActive;
bool hasValue() => isActive;
}
// An @override method inherits its name from the supertype and is exempt.
class Sub extends Flags {
Sub() : super(false);
@override
bool validate() => true;
}Configure boolean-prefixes
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"boolean-prefixes": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/boolean-prefixes: <reason>More style rules
- camel-case-extensions
camel_case_extensionsrecommendedFlags named extensions whose name is not
UpperCamelCase. - camel-case-types
camel_case_typesrecommendedFlags type names that are not
UpperCamelCase. - cast-nullable-to-non-nullable
cast_nullable_to_non_nullableFlags
e as Tcasts of a nullable value to a non-nullable type. - class-members-ordering
class_members_orderingFlags class members declared out of a canonical order.
- combinators-ordering
combinators_orderingFlags
show/hidecombinators whose names are not sorted alphabetically. - conditional-uri-does-not-exist
conditional_uri_does_not_existrecommendedRequire the targets of conditional import and export URIs to exist.
- constant-identifier-names
constant_identifier_namesrecommendedFlags constant identifiers that are not lowerCamelCase.
- curly-braces-in-flow-control-structures
curly_braces_in_flow_control_structuresrecommendedRequires curly braces around the bodies of flow-control statements.