rspec/rules/S2114/kotlin/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

33 lines
750 B
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,kotlin]
----
val objs = mutableListOf<Any>()
objs.add("Hello")
objs.add(objs) // Noncompliant; StackOverflowException if objs.hashCode() called
objs.addAll(objs) // Noncompliant; behavior undefined
objs.containsAll(objs) // Noncompliant; always true
objs.removeAll(objs) // Noncompliant; confusing. Use clear() instead
objs.retainAll(objs) // Noncompliant; NOOP
----
=== Compliant solution
[source,kotlin]
----
val newList = mutableListOf<Any>()
val objs = mutableListOf<Any>()
objs.add("Hello")
objs.containsAll(newList) // Compliant
objs.addAll(newList) // Compliant
objs.removeAll(newList) // Compliant
objs.retainAll(newList) // Compliant
----