rspec/rules/S2788/java/rule.adoc

36 lines
861 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Different formatters use different formatting symbols, and it can be easy to confuse one for the other. But get it wrong, and your output may be useless.
This rule logs an issue when the wrong type of format string is used for Guava, slf4j, logback or ``++MessageFormat++`` strings.
=== 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
----
String message = MessageFormat.format("Now is the %s %d all good people", "time", 4); // 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
----
String message = MessageFormat.format("Now is the {1} {2} all good people", "time", 4); // Noncompliant
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use "x" instead of "y" to format this [Guava|slf4j|logback|MessageFormat] message.
endif::env-github,rspecator-view[]