QL: Add query that finds 'if p() then q() else none()'.

This commit is contained in:
Mathias Vorreiter Pedersen
2021-10-13 09:48:57 +00:00
committed by GitHub
parent d99d02994a
commit c3f9d584a4

View File

@@ -0,0 +1,15 @@
/**
* @name Use of 'if' with a 'none()' branch.
* @description Using 'if p() then q() else none()' is bad style. It should be rewritten as 'p() and q()'.
* @kind problem
* @problem.severity warning
* @id ql/if-with-none
* @precision very-high
* @tags maintainability
*/
import ql
from IfFormula ifFormula
where ifFormula.getElsePart() instanceof NoneCall or ifFormula.getThenPart() instanceof NoneCall
select ifFormula, "Use a conjunction instead."