foldable_negation
Reports a negation the language can fold, such as !(a == b). Write the folded form, such as a != b.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- writes the expression without the
!
What it reports
Section titled “What it reports”The violation is on the negation:
!!readyon aboolthat cannot be null;!(a == b)and!(a != b);!(value is! T).
It does not report:
!(value is T), which the SDK lintprefer_is_not_operator(inrecommended) reports;!!on adynamicvalue, whose first!checks that it is abool;- a negated comparison of order:
!(ratio < 1)is notratio >= 1for NaN; - a negated
&&or||.
The fix adds brackets where the place of the negation needs them.
Each pair means the same by the language itself. The folded form reads as what it means.
Example
Section titled “Example”Violating
bool differ(int a, int b) => !(a == b);Corrected
bool differ(int a, int b) => a != b;Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: foldable_negation// ignore_for_file: assay/foldable_negation silences it in a whole file, and // ignore: assay/foldable_negation with the prefix works too. See Suppressions.