Modify rule S7054: fix typo in the Dart description

This commit is contained in:
Marharyta 2024-09-10 15:52:44 +02:00 committed by GitHub
parent 48df9b93a9
commit 7c46fffb13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,10 +1,10 @@
== Why is this an issue?
Dart has an `is` operator to check the type of a variable. This operator can also be used with negation `is!`. In this case we check that the type of a variable on the left side of the operator is not the one mentioned io the right side.
Dart has an `is` operator to check the type of a variable. This operator can also be used with negation `is!`. In this case we check that the type of a variable on the left side of the operator is not the one mentioned on the right side.
Similar operators also exist in other languages, but they might have different spelling. For example, in Kotlin, the same operator is written this way: `!is`. Developers familiar with both languages might confuse these 2 operators. Unfortunately, this won't lead to a compile time error, but will change the semantic of your code.
In Dart, `x is! Y`, will return `true` is `x` is not of type `Y` and will return `false`, if `x` is of type `Y`.
In Dart, `x is! Y`, will return `true` if `x` is not of type `Y` and will return `false`, if `x` is of type `Y`.
On the other hand `x !is Y` will apply null assertion operator (`!`) to `x` and then return `true` if `x` is of type `Y`, and return `false` if it is not.