avoid-unnecessary-negations
- Group
- Style
- Path
lint/style/avoid-unnecessary-negations- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 168 of 512
Simplifies negated bool literals and equality comparisons with a logical
negation on both sides. Stacked negations belong to
avoid-inverted-boolean-expressions; arithmetic, bitwise and relational
operators are deliberately excluded.
Invalid
bool trueLiteral() => !true;
bool falseLiteral() => !(false);
bool equal(bool flag, bool another) => !flag == !another;
bool unequal(bool flag, bool another) => (!flag) != (!another);
bool nested(bool a) => a && !true;
bool groupedEqual(bool a, bool b) => (!(a)) == (!(b));bool trueLiteral() => !true;bool trueLiteral() => !true;bool falseLiteral() => !(false);bool falseLiteral() => !(false);bool equal(bool flag, bool another) => !flag == !another;bool equal(bool flag, bool another) => !flag == !another;bool unequal(bool flag, bool another) => (!flag) != (!another);bool unequal(bool flag, bool another) => (!flag) != (!another);bool nested(bool a) => a && !true;bool nested(bool a) => a && !true;bool groupedEqual(bool a, bool b) => (!(a)) == (!(b));Valid
bool single(bool flag) => !flag;
bool equality(bool flag, bool another) => flag == another;
bool unequal(bool flag, bool another) => flag != another;
bool different(bool flag, bool another) => !flag == another;
bool conjunction(bool flag, bool another) => !flag && !another;
bool disjunction(bool flag, bool another) => !flag || !another;
int arithmetic(int value) => -(-value);
int bitwise(int value) => ~(~value);
bool relational(int a, int b) => !(a < b);
bool floating(double a, double b) => !(a >= b);
bool doubleNegation(bool flag) => !!flag;
bool parenthesized(bool flag) => !(!flag);
bool triple(bool flag) => !!!flag;
bool nested(bool a, bool b) => !!(a && !(!b));
bool stackedLiteral() => !!true;Configure avoid-unnecessary-negations
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-unnecessary-negations": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-unnecessary-negations: <reason>More style rules
- avoid-unnecessary-overrides-in-stateflutter
Redundant Flutter State overrides that drop inherited
@protected. - avoid-unnecessary-reassignment
Reports an eager local initializer immediately overwritten without a read.
- avoid-unnecessary-return
Flags bare returns at the end of a function or its final if/block branches.
- avoid-unnecessary-super
Omit implicit
super()initializers and provably redundant member prefixes. - avoid-unused-constructor-parameters
avoid_unused_constructor_parametersFlags constructor parameters that are never used.
- avoid-void-async
avoid_void_asyncrecommendedAvoid
asyncfunctions and methods declared to returnvoid. - avoid-wrapping-in-paddingflutter
Flags Padding directly wrapping a Flutter Container that can own the padding.
- binary-expression-operand-order
binary-expression-operand-orderFlags comparison expressions with a literal on the left-hand side.