From c3f9d584a4e59eac7a8267336f7a774a570a21d4 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 13 Oct 2021 09:48:57 +0000 Subject: [PATCH] QL: Add query that finds 'if p() then q() else none()'. --- ql/src/queries/style/IfWithElseNone.ql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ql/src/queries/style/IfWithElseNone.ql 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."