rspec/rules/S2200/java/rule.adoc
2022-02-04 16:28:24 +00:00

33 lines
564 B
Plaintext

While most ``++compareTo++`` methods return -1, 0, or 1, some do not, and testing the result of a ``++compareTo++`` against a specific value other than 0 could result in false negatives.
== Noncompliant Code Example
[source,java]
----
if (myClass.compareTo(arg) == -1) { // Noncompliant
// ...
}
----
== Compliant Solution
[source,java]
----
if (myClass.compareTo(arg) < 0) {
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]