CA - Complex Assignment

Checks for the occurrence of multiple assignments and assignments to variables within the same expression. Too complex assignments should be avoided since they decrease program readability.

If 'strict' option is off, assgnments of equal value to several variables in one operation is permited. For example the following statement would raise violation if 'strict' option is on, otherwise there would be no violation:

i = j = k = 0;

Wrong

// compound assignment
i *= j++;
k = j = 10;
l = j += 15;

// nested assignment
i = j++ + 20;
i = (j = 25) + 30;

Tip: Break statement into several ones.

Right

// instead of i *= j++;
j++;
i *= j

// instead of k = j = 10;
k = 10;
j = 10;

// instead of l = j += 15;
j += 15;
l = j;
// instead of i = j++ + 20;
j++;
i = j + 20;
// instead of i = (j = 25) + 30;
j = 25;
i = j + 30;