avoid-bitwise-operators-with-booleans
- Group
- Suspicious
- Path
lint/suspicious/avoid-bitwise-operators-with-booleans- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 22 of 512
Flags & and | applied to two non-nullable boolean operands.
Prefer && and || to express logical intent and short-circuit evaluation.
Both operands must resolve to core bool; integer, dynamic, nullable, and
unresolved operands are left alone. Exclusive-or and compound assignments
are not replacements for logical conjunction or disjunction.
Invalid
void example(bool left, bool right) {
final a = left & right;
final b = left | right;
final c = true & false;
final local = true;
final d = local | right;
final e = (left == right) & (a != b);
final f = (!left) | (!right);
}void example(bool left, bool right) { final a = left & right; final a = left & right; final b = left | right; final b = left | right; final c = true & false; final local = true; final d = local | right; final d = local | right; final e = (left == right) & (a != b); final e = (left == right) & (a != b); final f = (!left) | (!right);Valid
void example(bool left, bool right, int bits, dynamic unknown) {
final a = left && right;
final b = left || right;
final c = bits & 3;
final d = bits | 4;
final e = left ^ right;
final f = unknown & right;
left &= right;
left |= right;
}Configure avoid-bitwise-operators-with-booleans
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-bitwise-operators-with-booleans": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-bitwise-operators-with-booleans: <reason>More suspicious rules
- avoid-commented-out-code
Flags ordinary comments that contain recognizable Dart statements.
- avoid-double-slash-imports
Reject repeated path separators in directive URIs (import, export and part).
- avoid-dynamic
avoid-dynamicFlags explicit
dynamictype annotations. - avoid-empty-else
avoid_empty_elserecommendedFlags an
elseclause whose body is an empty statement (else ;). - avoid-ignoring-return-values
avoid-ignoring-return-valuesFlags a discarded call whose resolved return type is non-void.
- avoid-incorrect-uri
Reject runtime-invalid Uri constructor arguments: conflicting path or query inputs and query parameter values that are neither null, strings nor iterables of strings.
- avoid-inverted-boolean-checks
Prefer direct equality comparisons and De Morgan forms in control-flow conditions.
- avoid-multi-assignment
Split chained assignments into separate statements.