rspec/rules/S2761/java/rule.adoc

36 lines
818 B
Plaintext
Raw Normal View History

2020-12-23 14:59:06 +01:00
The needless repetition of an operator is usually a typo. There is no reason to write ``!!!i`` when ``!i`` will do.
2020-06-30 12:48:07 +02:00
On the other hand, the repetition of increment and decrement operators may have been done on purpose, but doing so obfuscates the meaning, and should be simplified.
2020-12-23 14:59:06 +01:00
This rule raises an issue for sequences of: ``!``, ``~``, ``-``, and ``\+``.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
----
int i = 1;
int j = - - -i; // Noncompliant; just use -i
int k = ~~~i; // Noncompliant; same as i
int m = + +i; // Noncompliant; operators are useless here
boolean b = false;
boolean c = !!!b; // Noncompliant
----
== Compliant Solution
----
int i = 1;
int j = -i;
int k = ~i;
int m = i;
boolean b = false;
boolean c = !b;
----
== Exceptions
2020-12-23 14:59:06 +01:00
Overflow handling for GWT compilation using ``~~`` is ignored.