rspec/rules/S2189/kotlin/rule.adoc

57 lines
825 B
Plaintext
Raw Normal View History

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
var j: Int
while (true) { // Noncompliant; end condition omitted
j++
}
var k: Int
val b = true
while (b) { // Noncompliant; b never written to in loop
k++
}
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
var j: Int = 0
while (true) { // reachable end condition added
j++
if (j == Int.MIN_VALUE) { // true at Integer.MAX_VALUE +1
break
}
}
var k: Int = 0
var b = true
while (b) {
k++
b = k < Int.MAX_VALUE
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]