Home

Boolean checks should not be inverted

Rule description

  • Boolean checks should not be inverted

 

Non-compliant Code Example

BEGIN

   IF NOT salary >= 20000 THEN       --Non compliant code (IF condition is having inverted boolean check)
      ILevel := 'Average Salary';

   ELSIF (NOT (salary < 20000)) and (NOT (salary >= 60000)) THEN  --Non compliant code (ELSE IF condition is having inverted boolean check)
      ILevel := 'Average Salary'; 

   ELSIF salary > 6000 and salary <= 110000 THEN
      ILevel := 'Moderate Salary';

   ELSE
      ILevel := 'High Salary';

   END IF;

END;

Compliant Code Example

BEGIN

   IF salary <= 20000 THEN      --Compliant code
      ILevel := 'Average Salary';

   ELSIF salary > 20000 and salary <= 60000 THEN --Compliant code
      ILevel := 'Average Salary'; 

   ELSIF salary > 6000 and salary <= 110000 THEN
      ILevel := 'Moderate Salary';

   ELSE
      ILevel := 'High Salary';

   END IF;

END;
Visual Expert 2020
 VEPLSQLRULE123