For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/dart-code-quality/prefer-is-not-operator.md. A documentation index is available at /llms.txt.

Use the is! operator instead of negating is

This product is not supported for your selected Datadog site. ().

Metadata

ID: dart-code-quality/prefer-is-not-operator

Language: Dart

Severity: Notice

Category: Code Style

Description

Negating a type test with !(x is T) is harder to read than the dedicated x is! T operator. Prefer the is! operator, which expresses the negated type check directly and improves readability.

Non-Compliant Code Examples

void main() {
  var x = 'a';
  var value = 1;
  if (!(x is String)) {}
  var b = !(value is int);
}

Compliant Code Examples

void main() {
  var x = 'a';
  var a = 1;
  var b = 2;
  var flag = true;

  if (x is! String) {}
  if (x is String) {}
  if (!(a == b)) {}
  if (!flag) {}
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security