rspec/rules/S1153/java/rule.adoc

64 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Appending ``++String.valueOf()++`` to a ``++String++`` decreases the code readability.
The argument passed to ``++String.valueOf()++`` should be directly appended instead.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void display(int i){
System.out.println("Output is " + String.valueOf(i)); // Noncompliant
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void display(int i){
System.out.println("Output is " + i); // Compliant
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Directly append the argument of String.valueOf().
'''
== Comments And Links
(visible only on this page)
=== on 16 Aug 2013, 12:51:37 Dinesh Bolkensteyn wrote:
\[~ann.campbell.2] I though you didn't like 'source code' ... but here it is "and decreases the readability of the source code" ;-)
=== on 16 Aug 2013, 14:30:04 Dinesh Bolkensteyn wrote:
The deprecatied rule covered also this case AFAIK:
----
String a = String.valueOf("foo");
----
which will not be covered by this rule.
=== on 16 Aug 2013, 15:20:24 Dinesh Bolkensteyn wrote:
Implemented by \http://jira.codehaus.org/browse/SONARJAVA-241
=== on 17 Aug 2013, 15:54:50 Ann Campbell wrote:
I don't [~dinesh.bolkensteyn]], but without a list of rules, I try to conform to what appears to be the established standard. :-)
endif::env-github,rspecator-view[]