rspec/rules/S2358/dart/rule.adoc

46 lines
945 B
Plaintext

== Why is this an issue?
``++is!++`` operator is used to check if an object is not of a specified type. While ``++ x is! Y++`` is an equivalent of ``++!(x is Y)++``, it is preferred to use the first one.
The ``++ x is! Y++`` syntax is more compact and more readable than the ``++!(x is Y)++`` syntax. It is also less error-prone when used in complex expressions.
=== Noncompliant code example
[source,dart]
----
if (!(x is Y)) {
print("$x is not Y!")
}
----
=== Compliant solution
[source,dart]
----
if (x is! Y) {
print("$x is not Y!")
}
----
== Resources
* Dart Docs - https://dart.dev/tools/linter-rules/prefer_is_not_operator[Dart Linter rule - prefer_is_not_operator]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use the 'is!' operator rather than negating the value of the 'is'
=== Highlighting
The prefix expression
endif::env-github,rspecator-view[]