Inspectopedia
 
2024.3

'if' statement with negated condition

Warning
New
Last modified: 03 December 2024

Reports if statements that contain else branches and whose conditions are negated.

Flipping the order of the if and else branches usually increases the clarity of such statements.

There is a fix that inverts the current if statement.

Example:

After applying the quick-fix:

Use the Ignore '!= null' comparisons option to ignore comparisons of the != null form.

Use the Ignore '!= 0' comparisons option to ignore comparisons of the != 0 form.