From c49c69ed9f2c285db7aded15bef86296986deeb8 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 6 Jun 2021 04:12:56 +1000 Subject: [PATCH] Early return in CountVisitor if macro node Co-authored-by: Sijawusz Pur Rahnama --- src/ameba/ast/visitors/counting_visitor.cr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ameba/ast/visitors/counting_visitor.cr b/src/ameba/ast/visitors/counting_visitor.cr index 2ab64231..896baa64 100644 --- a/src/ameba/ast/visitors/counting_visitor.cr +++ b/src/ameba/ast/visitors/counting_visitor.cr @@ -32,10 +32,12 @@ module Ameba::AST # :nodoc: def visit(node : Crystal::Case) + return true if macro_condition + # Count the complexity of an exhaustive `Case` as 1 # Otherwise count the number of `When`s - case_complexity = node.exhaustive? ? 1 : node.whens.size - @complexity += case_complexity unless macro_condition + @complexity += node.exhaustive? ? 1 : node.whens.size + true end