diff --git a/ql/src/queries/style/IfWithElseNone.ql b/ql/src/queries/style/IfWithElseNone.ql new file mode 100644 index 00000000000..c563c28e9f8 --- /dev/null +++ b/ql/src/queries/style/IfWithElseNone.ql @@ -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."