rspec/rules/S1153/java/rule.adoc

60 lines
1.3 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
Appending `String.valueOf()` to a `String` decreases the code readability.
2021-04-28 16:49:39 +02:00
The argument passed to `String.valueOf()` should be directly appended instead.
2021-04-28 16:49:39 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
String message = "Output is " + String.valueOf(12);
2021-04-28 16:49:39 +02:00
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
String message = "Output is " + 12;
2021-04-28 16:49:39 +02:00
----
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[]