Using the same value on both sides of certain operators is a code defect. In the case of logical operators, it is either a copy/paste error and,
therefore, a bug, or it is simply duplicated code and should be simplified. For comparison operators and arithmetic operations, having the same value
on both sides of an operator yields predictable results and should be simplified as well to avoid further code defects.
This rule raises for the following operators and constructs in bash/shell:
- Equality operators (
==
, !=
, =
)
- Comparison operators (
-eq
, -ne
, -lt
, -le
, -gt
, -ge
)
- String comparison operators (
<
, >
)
- Logical operators (
&&
, ||
)
- Regex operator (
=~
)
- Arithmetic operations in
$expression
:
- Subtraction (
-
)
- Division (
/
)
- Modulo (
%
)
- Bitwise operations in
$expression
:
- Bitwise OR (
|
)
- Bitwise AND (
&
)
- Bitwise XOR (
^
)
Exceptions
This rule ignores the following operators:
- Multiplication (
*
)
- Exponentiation (
**
)
- Addition (
+
)
- Assignment (
=
when used for variable assignment)
- Bitwise shift operators (
<<
, >>
)