prefer-is-not-operator
Same as prefer_is_not_operator in Dart lints
- Group
- Style
- Path
lint/style/prefer-is-not-operator- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 378 of 512
Flags a negated type test !(x is T) that should use the is! operator.
Dart provides the is! operator precisely so negated type checks read
directly as x is! T instead of wrapping the test in parentheses and negating
it, which is easier to misread and to accidentally mis-parenthesize. The rule
fires on a logical-not applied to a non-negated is expression; a test that
already uses is! produces no negation to flag.
Invalid
void f(Object x) {
if (!(x is int)) {}
var a = !(x is String);
final b = !(x is List<int>);
final c = !(x is double);
print(!(x is bool));
print('$a $b $c');
}void f(Object x) { if (!(x is int)) {} if (!(x is int)) {} var a = !(x is String); var a = !(x is String); final b = !(x is List<int>); final b = !(x is List<int>); final c = !(x is double); final c = !(x is double); print(!(x is bool));Valid
void f(Object x) {
if (x is! int) {}
var a = x is String;
final b = !(x is! double);
var c = !someBool(x);
print(x is bool);
print('$a $b $c');
}
bool someBool(Object x) => true;Configure prefer-is-not-operator
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-is-not-operator": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-is-not-operator: <reason>More style rules
- prefer-iterable-of
prefer-iterable-ofrecommendedFlags
.fromcollection constructors in favor of the.ofconstructor. - prefer-iterable-where-type
prefer_iterable_whereTyperecommendedFlags
.where((e) => e is T), which.whereType<T>()expresses directly. - prefer-last
prefer-lastFlags manual last-element indexing in favor of the
.lastgetter. - prefer-match-file-name
Match a file's sole class or enum name to its snake-case basename.
- prefer-mixin
prefer_mixinrecommendedFlags
withclauses that mix in a plain class instead of a mixin. - prefer-multi-bloc-providerbloc
Flatten directly nested
package:flutter_blocBlocProviderswithMultiBlocProvider. - prefer-multi-providerprovider
Prefer a flat
MultiProviderto directly nested provider widgets. - prefer-named-boolean-parameters
Flags explicit positional
boolparameters in private declarations and unconstrained closures.