avoid-bitwise-operators-with-booleans
Warns when a bitwise operator (&
or |
) is used with a boolean expression.
⚙️ Config
Set ignore-assignments
(default is true
) to ignore bitwise operators usage in assignments.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-bitwise-operators-with-booleans:
ignore-assignments: true
Example
❌ Bad:
void fn() {
var x = true;
// LINT: Avoid bitwise operators with boolean expression. Try using a logical operator instead.
if (x & false) {
// ...
}
// LINT: Avoid bitwise operators with boolean expression. Try using a logical operator instead.
if (x | false) {
// ...
}
}
✅ Good:
void fn() {
var x = true;
if (x && false) {
// ...
}
if (x || false) {
// ...
}
}