Changed title and description for Kotlin, since arrays have "size" instead or "length" (#1444)

This commit is contained in:
leonardo-pilastri-sonarsource 2022-12-02 17:19:14 +01:00 committed by GitHub
parent 3f6a2c59ab
commit 7e6b7ebe1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,8 @@
== Compliant Solution
[source,text]
----
if (!myList.isEmpty()) { ... }
if (myArray.size >= 42) { ... }
----

View File

@ -0,0 +1 @@
The size of a collection or an array is always greater than or equal to zero. So testing that a size is greater than or equal to zero doesn't make sense, since the result is always `true`. Similarly testing that it is less than zero will always return `false`. Perhaps the intent was to check the non-emptiness of the collection or array instead.

View File

@ -1,3 +1,3 @@
{
"title": "Collection and array sizes comparisons should make sense"
}

View File

@ -0,0 +1,12 @@
== Noncompliant Code Example
[source,text]
----
if (myList.size >= 0) { ... }
if (myList.size < 0) { ... }
boolean result = myArray.size >= 0;
if (0 > myArray.size) { ... }
----

View File

@ -1,4 +1,8 @@
include::../rule.adoc[]
include::description.adoc[]
include::noncompliant.adoc[]
include::compliant.adoc[]
ifdef::env-github,rspecator-view[]