rspec/rules/S2761/java/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

58 lines
1.2 KiB
Plaintext

== Why is this an issue?
The repetition of a unary operator is usually a typo. The second operator invalidates the first one in most cases:
[source,java]
----
int i = 1;
int j = - - -i; // Noncompliant: equivalent to "-i"
int k = ~~~i; // Noncompliant: equivalent to "~i"
int m = + +i; // Noncompliant: equivalent to "i"
boolean b = false;
boolean c = !!!b; // Noncompliant
----
On the other hand, while repeating the increment and decrement operators is technically correct, it obfuscates the meaning:
[source,java]
----
int i = 1;
int j = ++ ++i; // Noncompliant
int k = i-- --; // Noncompliant
----
Using ``+=`` or ``-=`` improves readability:
[source,java]
----
int i = 1;
i += 2;
int j = i;
int k = i;
i -=2;
----
This rule raises an issue for repetitions of ``++!++``, ``++~++``, ``++-++``, ``{plus}``, prefix increments ``{plus}{plus}`` and prefix decrements ``--``.
=== Exceptions
Overflow handling for GWT compilation using ``++~~++`` is ignored.
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[]