prefer-boolean-prefixes
Suggests to prefix boolean variables, methods, fields and parameters with one of the configured prefixes.
⚙️ Config
Set ignored-names (default is empty) to ignore specific function / method names.
Set ignore-methods (default is false) to exclude methods.
Set ignored-annotations (default is empty) to ignore declarations with specific annotations.
Set ignore-fields (default is false) to exclude fields.
Set ignore-parameters (default is false) to exclude parameters.
Set prefixes (default is [is, are, was, were, has, have, had, can, should, will, do, does, did]) to configure the list of allowed prefixes.
analysis_options.yaml
dcm:
rules:
- prefer-boolean-prefixes:
ignore-fields: false
ignore-methods: false
ignore-parameters: false
ignored-annotations:
- someAnnotation
ignored-names:
- some
- name
prefixes:
- is
- are
Example
❌ Bad:
class Some {
// LINT: This declaration has a boolean type, but is not named with a valid prefix.
// Try renaming this declaration.
final bool test;
// LINT: This declaration has a boolean type, but is not named with a valid prefix.
// Try renaming this declaration.
final bool isnotcorrect;
// LINT: This declaration has a boolean type, but is not named with a valid prefix.
// Try renaming this declaration.
final bool _private;
// LINT: This declaration has a boolean type, but is not named with a valid prefix.
// Try renaming this declaration.
bool someRandom() => false;
}
✅ Good:
class Some {
final bool hasTest;
final bool isCorrect;
final bool _isPrivate;
bool isCorrectMethod() => true;
}