Changed title and description for Kotlin, since arrays have "size" instead or "length" (#1444)
This commit is contained in:
parent
3f6a2c59ab
commit
7e6b7ebe1d
8
rules/S3981/kotlin/compliant.adoc
Normal file
8
rules/S3981/kotlin/compliant.adoc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
== Compliant Solution
|
||||||
|
|
||||||
|
[source,text]
|
||||||
|
----
|
||||||
|
if (!myList.isEmpty()) { ... }
|
||||||
|
|
||||||
|
if (myArray.size >= 42) { ... }
|
||||||
|
----
|
1
rules/S3981/kotlin/description.adoc
Normal file
1
rules/S3981/kotlin/description.adoc
Normal 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.
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
|
"title": "Collection and array sizes comparisons should make sense"
|
||||||
}
|
}
|
||||||
|
12
rules/S3981/kotlin/noncompliant.adoc
Normal file
12
rules/S3981/kotlin/noncompliant.adoc
Normal 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) { ... }
|
||||||
|
----
|
@ -1,4 +1,8 @@
|
|||||||
include::../rule.adoc[]
|
include::description.adoc[]
|
||||||
|
|
||||||
|
include::noncompliant.adoc[]
|
||||||
|
|
||||||
|
include::compliant.adoc[]
|
||||||
|
|
||||||
ifdef::env-github,rspecator-view[]
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user